Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I save the points value in this code?

local intv = 1
local pointsGiven = 1

-------------------------------------------

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
	
    local Points = Instance.new("IntValue")
    Points.Name = "Points"
    Points.Value = 0
    Points.Parent = leaderstats
end)

while wait(intv) do 
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player:FindFirstChild("leaderstats") then
			
            player.leaderstats.Points.Value = player.leaderstats.Points.Value + pointsGiven
        end
    end
end

I know, DataStores, but I can't figure out the actual code.

1 comment

0

I've been at this for 3 hours BTW, I'm getting stressed out.

1 answer

✓ Accepted answer

Hello.

There is an easy pre-built feature in roblox's API wich saves Points and loads them.

This can be simply done by replacing Points.Value in PlayerAdded with Points.Value=player:LoadNumber("pts")

And then you just need to add a PlayerRemoving:

game.Players.PlayerRemoving:connect(function(p)
	p:SaveNumber("pts",p:WaitForChild('leaderstats'):WaitForChild('Points').Value)
end)

Have fun and good luck!, marcoantoniosantos3

This discussion is preserved as it was. New answers, comments, and votes are closed.