Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you save a number with datastore?

Asked by 7 years ago

I have been trying to save a number with data stores but it doesn't save ;L

It also interferes with another save system and it doesn't save the other value

local DataStore = game:GetService("DataStoreService")
local ds3 = DataStore:GetDataStore("MaxHealthSaveSystem")

game.Players.PlayerAdded:connect(function(player)
    local maxhealth = workspace:WaitForChild(player).Humanoid.MaxHealth
    ds3:SetAsync(player.UserId, maxhealth.Value)
    maxhealth.Changed:connect(function()
        ds3:SetAsync(player.UserId, maxhealth)
    end)
end)

game.Players.PlayerRemoving:connect(function(player)
    local maxhealth = workspace:WaitForChild(player).Humanoid.MaxHealth
    ds3:SetAsync(player.UserId, maxhealth)
end)

0
Idk if it matters, but I don't use numbers in my variables. Crazycat4360 115 — 7y
0
It matters crazy cat greatneil80 2647 — 7y
0
That would error on the fifth line, since you're passing a Player instance to WaitForChild instead of a string. Sir_Melio 221 — 7y

Answer this question