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

Can someone help fix this script? its a saving system for my tower defense game TW(TowerWars

Asked by 3 years ago

Please Check It could not save tower datas

local data = game:GetService("DataStoreService"):GetDataStore("TowerDataStore") function save(plr)

local saveData = {}
for i, v in pairs(plr:GetChildren())do
    if v:IsA("StringValue") then
        saveData[v.Name] = v.Value
    end
end
data:SetAsync(plr.UserId, saveData)

end

game.Players.PlayerAdded:Connect(function(plr) for i = 1, 5 do local x = Instance.new("StringValue", plr) x.Name = "Tower"..tostring(i) x.Value = "Empty" end local getData local success, errorm = pcall(function() getData = data:GetAsync(plr.UserId) end) if success then if getData then for i, v in pairs(getData) do plr:FindFirstChild(i).Value = v end end end end)

game:BindToClose(function() for _, v in pairs(game.Players:GetChildren()) do wait(10) save(v) end end) game.Players.PlayerRemoving:Connect(function(plr) wait(10) save(plr) end)

2 answers

Log in to vote
0
Answered by 3 years ago

move the BindToClose:() function to be inside of the PlayerRemoving function. I guess that will do

0
that didnt dj2098091 3 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

This question is a copy of this question. There is a fun feature known as "edit" so you don't have to post another post if you make an error.

Answer this question