Hi, I made it so every 60 seconds or 1 minute, you get 50 cash, but It doesn't save, how do I use datastorage? pls help, thanks.
function onPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local cash = Instance.new("IntValue") cash.Name = "Cash" cash.Value = 100 cash.Parent = stats stats.Parent = newPlayer while true do cash.Value = cash.Value + 50 wait(60) end end game.Players.ChildAdded:connect(onPlayerEntered)
This is a pretty simple script I made for my game. In my game, I made it so it saves the minutes (currency) of the player on the leaderboard. Here's the script
function onPlayerEntered(player) wait()-- Change to wait for player longer. player:WaitForDataReady() repeat wait() until player:FindFirstChild("leaderstats") if player.DataReady then if player:findFirstChild("leaderstats") then local score = player.leaderstats:GetChildren() for i = 1,#score do local ScoreLoaded = player:LoadNumber(score[i].Name) wait() if ScoreLoaded ~= 0 then score[i].Value = ScoreLoaded end end end end end function onPlayerLeaving(player) if player:findFirstChild("leaderstats") then local score = player.leaderstats:GetChildren() for i = 1,#score do player:SaveNumber(score[i].Name,score[i].Value) end end end game.Players.PlayerAdded:connect(onPlayerEntered) game.Players.PlayerRemoving:connect(onPlayerLeaving)
Marked as Duplicate by Shawnyg
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?