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

How do I save the points value in this code?

Asked by
Jephi 42
8 years ago
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.

0
I've been at this for 3 hours BTW, I'm getting stressed out. Jephi 42 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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

Ad

Answer this question