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

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

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

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

1 comment

0

that didnt

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.

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