I figured out the issue, the script works however the BindToClose isn’t working. It isn’t even working for me. The issue is how it was in the beginning. There is not enough time to save the players data.
With the bind to close it is endlessly sending requests. We do not want that which why I disabled it in my script. Give me a second and I will fix this.
Ok cool tysm for all your help!!!
game:BindToClose(function()
local LastPlayer = nil
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
local player_stats = {}
if player then
if player ~= LastPlayer then
for i, stat in pairs(player:WaitForChild("leaderstats"):GetChildren()) do
player_stats[stat.Name] = stat.Value
end
end
playerData:SetAsync("Player_"..player.UserId, player_stats)
end
end
end)
I thought I could do it another way but I couldn’t. This should work.
Good luck and enjoy your coding!
Sorry for the bad mood but I am just tired and dealt with a lot of errors in my friends game.
Hey man its ok. Ive been trying to get this fixed ALL week. Thank you so much for helping me.
I tested it in a test game but like I said if you get any errors because of the bind to close just delete it knowing it works in the actual game.
No problem and feel free to message me on roblox if something goes wrong again with the scripts I gave you.
I also will make the script I sent to you public so you can use it because I think you will find stuff in there that will improve your coding
Mind if I friend you?
Sure and good luck!
Although don’t you need the sell script working?
Ya I do…
Alright we will fix that and put all solves into one comment so everybody can see it. You can mark that comment as solved
Wait. OH SNAAAP. The save data works. AND NOW THE SELL WORKS ALSO. Alright then I guess your services are no longer needed tysm dude.
Edit: Tested it on normal roblox. Works great
alright let me right it into one post
Here is the dataSave,
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("playerData")
local checktable = {}
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local souls = Instance.new("IntValue")
souls.Name = "Souls"
souls.Parent = leaderstats
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = leaderstats
local playerUserId = player.UserId
local data = playerData:GetAsync("Player_"..playerUserId)
if data then
souls.Value = data['Souls']
coins.Value = data['Coins']
else
souls.Value = 50
coins.Value = 1
end
end
local function onPlayerExit(player)
local player_stats = {}
if player then
for i, stat in pairs(player:WaitForChild("leaderstats"):GetChildren()) do
player_stats[stat.Name] = stat.Value
end
playerData:SetAsync("Player_"..player.UserId, player_stats)
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)
game:BindToClose(function()
local LastPlayer = nil
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
local player_stats = {}
if player then
if player ~= LastPlayer then
for i, stat in pairs(player:WaitForChild("leaderstats"):GetChildren()) do
player_stats[stat.Name] = stat.Value
end
end
playerData:SetAsync("Player_"..player.UserId, player_stats)
end
end
end)
DataSave was error with sell too though I would recommend spacing out the >= from the variables
Nice! Thank you so much dude. Now I can FINALLY start making progress on my video game. Tysm.
DM me on roblox if you need any assistance if I don’t respond in 15 mins take it to the forums
k Thanks again!!!
as a way to make the forums a little less clouded