Ive been having trouble adding a BindToClose() function to this script. Thanks for your help
local DataStoreService = game:GetService("DataStoreService")
local SaveDataStore = DataStoreService:GetDataStore("PlayerSpeed")
game.Players.PlayerRemoving:Connect(function(player)
local p = player:FindFirstChild("WalkspeedShop")
if p then
local savedata = {}
for i, v in pairs(p:GetChildren()) do
savedata[v.Name] = v.Value
end
SaveDataStore:SetAsync(player.UserId, savedata)
end
end)
game.Players.PlayerAdded:Connect(function(player)
local WalkspeedShop = Instance.new("Folder")
WalkspeedShop.Name = "WalkspeedShop"
WalkspeedShop.Parent = player
local W20 = Instance.new("BoolValue")
W20.Name = "W20"
W20.Parent = WalkspeedShop
local W23 = Instance.new("BoolValue")
W23.Name = "W23"
W23.Parent = WalkspeedShop
local W25 = Instance.new("BoolValue")
W25.Name = "W25"
W25.Parent = WalkspeedShop
local W26 = Instance.new("BoolValue")
W26.Name = "W26"
W26.Parent = WalkspeedShop
local W27 = Instance.new("BoolValue")
W27.Name = "W27"
W27.Parent = WalkspeedShop
local W28 = Instance.new("BoolValue")
W28.Name = "W28"
W28.Parent = WalkspeedShop
local W29 = Instance.new("BoolValue")
W29.Name = "W29"
W29.Parent = WalkspeedShop
local W30 = Instance.new("BoolValue")
W30.Name = "W30"
W30.Parent = WalkspeedShop
local data = SaveDataStore:GetAsync(player.UserId)
if data then
print("Data loaded")
for i,v in pairs(WalkspeedShop:GetChildren()) do
v.Value = data[v.Name]
end
end
while wait(240)do
local p = player:FindFirstChild("WalkspeedShop")
if p then
local savedata = {}
for i, v in pairs(p:GetChildren()) do
savedata[v.Name] = v.Value
end
SaveDataStore:UpdateAsync(player.UserId, savedata)
end
end
end)

2 comments
I added your code and it works, but i get this message? DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 238723381
Use only 2 SetAsyncs (one for player removing and other for game:BindToClose() and one GetAsync. Don't attempt to use more.