local datastore = game:GetService("DataStoreService") local ds1 = datastore:GetDataStore("sAvePLR_Dataa") game.Players.PlayerAdded:connect(function(plr) local coins = Instance.new("IntValue", plr) coins.Name = "Coins" local rubys = Instance.new("IntValue", plr) rubys.Name = "Rubys" local function getData() local getSave = ds1:GetAsync(plr.UserId) if getSave then coins.Value = getSave[1] rubys.Value = getSave[2] else local savetable = { coins.Value, rubys.Value, } ds1:SetAsync(plr.UserId, savetable) end end local pass = false repeat local pass, msg = pcall(getData) wait() until pass game.Players.PlayerRemoving:connect(function(plr) local savetable = { coins.Value, rubys.Value, } ds1:SetAsync(plr.UserId, savetable) end) game:BindToClose(function() local savetable = { coins.Value, rubys.Value, } ds1:SetAsync(plr.UserId, savetable) end) end) game:BindToClose(function() for i, player in pairs(game.Players:GetPlayers()) do if player then player:Kick("this game has shutdown") end end wait(5) end)
This script doesn't save data when I test it in studio, this script disappears from ServerScriptService is there any reason why this script disappears and doesn't save players data?
If you know the answer, please let me know. I'm very confused about why this isn't working.
Ok first off, scripts just disappear from the ServerScriptService, it's supposed to happen. They are still the child to the ServerScriptService, but they just aren't there. Next, you shouldn't be declaring a function, inside a function. declare the getData function outside of the first function. Then send paramters through to the getData function. Same goes for the "game.Players.PlayerRemoving" and "BindToClose". In the BindToClose outside of the "Player.PlayerAdded" function, save their data and then kick them, so that the other one inside the playeradded function is not needed. One last thing - any errors?