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

My game isn't saving data, how can I fix this critical issue?

Asked by 5 years ago

I have a datastore that is supposed to save the points of the player, for some reason, it doesn't work and because it is wrapped in a pcall, it does not send an error to fix.

Here the points script: (Works)


game.Players.PlayerAdded:connect(function(plr) local ls = plr:WaitForChild("leaderstats") local rank = Instance.new("IntValue",ls) rank.Name = "Points" rank.Value = 0 while true do rank.Value = rank.Value + 5 wait(5) end end)

Here is the data script: (Does not work)

local dataStores = game:GetService("DataStoreService"):GetDataStore("ExtolDataStore")
local players = 0

game.Players.PlayerAdded:connect(function(plr)
    players = players + 1

    local points = plr:WaitForChild("leaderstats"):WaitForChild("Points").Value


    local player_data

pcall(function()
     player_data = dataStores:GetAsync("user_"..plr.UserId,points)
end)

if player_data ~= nil then
    points = player_data else
    points = 0
end

end)


local bindableEvent = Instance.new("BindableEvent")

game.Players.PlayerRemoving:connect(function(plr)
    local points = plr:WaitForChild("leaderstats"):WaitForChild("Points").Value

    pcall(function()
        dataStores:SetAsync("user_"..plr.UserId,points)
        print("Saved "..plr.Name.."'s Data")
        players = players - 1
        bindableEvent:Fire()
    end)

    game:BindToClose(function()
    while players > 0 do
        bindableEvent.Event:Wait()
    end
    end)
end)

Thank you to anyone who can help.

0
Is the Value property not updating when your points variable is updated? User#24403 69 — 5y

1 answer

Log in to vote
-3
Answered by 5 years ago
  1. Why are you using pcall in the first place?
  2. You'll have to handle saving and all that in the pcall it self, if this doesn't work then don't use pcall............
0
What a half assed response. User#24403 69 — 5y
Ad

Answer this question