of     1   

1billybob1
#141131589Tuesday, July 22, 2014 3:42 AM GMT

Okay, so I am creating a script in which when you click a button (on a gui), your heath increases. The health increasing, however, is in another script. This is the saving one. I want the health to be the same amount the player upgraded it to after the player respawns. It does work at first, but then I encounter problems (no error in the output though, sadly.) It will work until I reset. (ex. the health increases by 10 every time you click 'again, the health increases in another script, but that's not the problem.' so in this case, let's say I increased it to 120. After I reset, it will load 120 health and maxhealth. But then, after I RESET (bold that word) if I upgrade the health again and reset again, it will just stay at 120 again, and again, and again. I have no idea how I'd fix it, I've tried adding a wait after clicking the button, adding a return end at the end of the button clicking, but I just can't find out why it doesn't work once the player respawns. THINGS TO KNOW: -All variables are tagged (earlier in the script, this is just the problematic part.) -This is in a server script located in Workspace. I know this is long, but I'd appreciate it SO MUCH if you can help! Thanks if you can!!! Here's the script: player.PlayerGui:WaitForChild("Shop").Frame.Upgrades.Health:WaitForChild("Upgrade").MouseButton1Down:connect(function() if player.PlayerGui:WaitForChild("Shop").Frame.Upgrades.Health:WaitForChild("Upgrade").Text ~= "UPGRADE" then return end wait(0.5) local ds3 = game:GetService("DataStoreService"):GetDataStore("Upgrade_Health") local price = player.PlayerGui.Shop.Frame.Upgrades.Health.Price local humanoidz = player.Character.Humanoid local key = "user_".. player.userId ds3:UpdateAsync(key, function(oldValue) local newValue = price.Value or 0 return newValue end) local key = "user_" .. player.userId ds3:UpdateAsync(key, function(oldValue) local newValue = humanoidz.MaxHealth or 0 return newValue end) local key = "user_" .. player.userId ds3:UpdateAsync(key, function(oldValue) local newValue = humanoidz.Health or 0 return newValue end) return end) player.CharacterAdded:connect(function(char) local ds3 = game:GetService("DataStoreService"):GetDataStore("Upgrade_Health") local price = player.PlayerGui.Shop.Frame.Upgrades.Health.Price local humanoidz = player.Character.Humanoid local key = "user_"..player.userId price.Value = ds3:GetAsync(key, price.Value) humanoidz.MaxHealth = ds3:GetAsync(key, humanoidz.MaxHealth) humanoidz.Health = ds3:GetAsync(key, humanoidz.Health) return end)
1billybob1
#141135171Tuesday, July 22, 2014 4:25 AM GMT

b1
ArbiterOfDeath
#141138794Tuesday, July 22, 2014 5:15 AM GMT

I'm testing it, give me a moment.
ArbiterOfDeath
#141139783Tuesday, July 22, 2014 5:30 AM GMT

You had some simple problems with your keys, the GetUpdateFunction, and tried to access the humanoid without waiting for it. Try this: local button = player.PlayerGui:WaitForChild("Shop").Frame.Upgrades.Health:WaitForChild("Upgrade") button.MouseButton1Down:connect(function() if button.Text ~= "UPGRADE" then return end wait(0.5) local ds3 = game:GetService("DataStoreService"):GetDataStore("Upgrade_Health") local price = button.Price if not player.Character then return end --GUI is about to reload local humanoid = player.Character:WaitForChild("Humanoid") local key = "user_".. player.userId ds3:UpdateAsync(key .. "Price", function(oldValue) local newValue = price.Value or 0 return newValue end) ds3:UpdateAsync(key .. "MaxHealth", function(oldValue) local newValue = humanoidz.MaxHealth or 0 return newValue end) ds3:UpdateAsync(key .. "Health", function(oldValue) local newValue = humanoidz.Health or 0 return newValue end) end) player.CharacterAdded:connect(function(char) local ds3 = game:GetService("DataStoreService"):GetDataStore("Upgrade_Health") local price = button.Price local humanoidz = char:WaitForChild("Humanoid") local key = "user_" .. player.userId price.Value = ds3:GetAsync(key .. " Price") humanoidz.MaxHealth = ds3:GetAsync(key .. "MaxHealth") humanoidz.Health = ds3:GetAsync(key .. "Health") end)
1billybob1
#141163606Tuesday, July 22, 2014 2:24 PM GMT

I had to tweak it up a bit; there were a few problems with loading it, but once I got it to work, it did the same exact thing my last script did. It works at first, but once you reset and try upgrading it again; it doesn't save the upgraded health anymore. (another ex. I had 100, I upgrade it to 120, reset, works fine. Then I try doing it again. I upgrade to 150. Reset. It never saved 150, instead, it goes back to 120.
1billybob1
#141163656Tuesday, July 22, 2014 2:25 PM GMT

local button = player.PlayerGui:WaitForChild("Shop").Frame.Upgrades.Health:WaitForChild("Upgrade") local price = button.Price button.MouseButton1Down:connect(function() if button.Text ~= "UPGRADE" then return end wait(0.5) local ds3 = game:GetService("DataStoreService"):GetDataStore("Upgrade_Health") if not player.Character then return end --GUI is about to reload local humanoidz = player.Character:WaitForChild("Humanoid") local key = "user_".. player.userId ds3:UpdateAsync(key .. "Price", function(oldValue) local newValue = price.Value or 0 return newValue end) ds3:UpdateAsync(key .. "MaxHealth", function(oldValue) local newValue = humanoidz.MaxHealth or 0 return newValue end) ds3:UpdateAsync(key .. "Health", function(oldValue) local newValue = humanoidz.Health or 0 return newValue end) end) player.CharacterAdded:connect(function(char) local ds3 = game:GetService("DataStoreService"):GetDataStore("Upgrade_Health") local humanoidz = char:WaitForChild("Humanoid") local key = "user_" .. player.userId price.Value = ds3:GetAsync(key .. " Price") humanoidz.MaxHealth = ds3:GetAsync(key .. "MaxHealth") humanoidz.Health = ds3:GetAsync(key .. "Health") end)
BothAngles
#141164936Tuesday, July 22, 2014 2:49 PM GMT

not even using datastore right lmao its a good thing bad developers arent good at LUA
1billybob1
#141165817Tuesday, July 22, 2014 3:02 PM GMT

@BothAngles Yup, totally. I'm such a bad developer just because I'm still in the process of learning datastores. Yeah, I think we should all listen to this 65-post arrogant alternative account, in which they are too much a wuss to post on their main account. Please, little frooblet, return home.
BothAngles
#141166237Tuesday, July 22, 2014 3:07 PM GMT

i don't post on the forums with my main u m0re on im gonna laugh when u exceed the request limit and dont no y ur data isnt saving
1billybob1
#141166533Tuesday, July 22, 2014 3:12 PM GMT

@BothAngles Yeah, quite obvious you don't post on your main- because if you did you'd be the flame bait. And I hope you have a good laugh. Enjoy the show.

    of     1