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

My Datastore script is not working, it keeps putting the value as 0. ?

Asked by 4 years ago
Edited 4 years ago

local dss = game:GetService("DataStoreService") local mds = dss:GetDataStore("money")

game.Players.PlayerAdded:Connect(function(player) local menu = player.PlayerGui:WaitForChild("bucks") local money = menu.money local data local success, errormessage = pcall(function() data = mds:GetAsync(player.UserId.."-bucks") end)

if success then
    money.Value = data
    print("successfully loaded data")
else
    print("error while loading data")
    warn(errormessage)
end

end)

game.Players.PlayerRemoving:Connect(function(player) local menu = player.PlayerGui:WaitForChild("bucks") local money = menu.money local success, errormessage = pcall(function() mds:SetAsync(player.UserId.."-bucks",money.Value) end)

if success then
    print("Successfully saved players data!")
else
    print("There was an error while saving the players data.")
    warn(errormessage)
end

end)

1 answer

Log in to vote
0
Answered by
XDvvvDX 186
4 years ago
Edited 4 years ago

As in my understanding. I see that you've stored the values (Money, Bucks) in PlayerGui... To do this kind of act you'll have to store a Folder called "leaderstast" inside of the player. Like this :

game.Players.PlayerAdded:Connect(function(plr) --Rememeber this parameter.
   local LeadFolder = Instance.new("Folder")
   LeadFolder.Name = "leaderstats"
   LeadFolder.Parent = plr --The parameter we setted earlier.

   local Money = Instance.new("IntValue")
   Money.Parent = LeadFolder
   Money.Name = "Money"

   local Bucks = Instance.new("IntValue")
   Bucks.Parent = LeadFolder
   Bucks.Name = "Bucks"
end)

That's how you instance a leaderstats folder correctly and values inside of it. And as I see the you've defined bucks down in the line as :

player.PlayerGui:WaitForChild("Bucks")

That's incorrect to store values inside of PlayerGui and expect for them to be leaderstats. If it's not the issue, react to this message for further questions. No problem, Programmer XDvvvDX.

Ad

Answer this question