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)
move the BindToClose:()
function to be inside of the PlayerRemoving
function. I guess that will do
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.