Basically I made a save program. Whenever it's supposed to save and execute success, it executed the error warning. Please help!

local DataStoreService = game:GetService("DataStoreService")
local PlayerData = DataStoreService:GetDataStore("PlayerData")
local X = 0

game.Players.PlayerAdded:Connect(function(plr)
	
	local SpendingCoins = script.Parent.Parent.Workspace.Players:WaitForChild(""..plr.DisplayName).SpendingCoins
	
	local UserID = "Player"..plr.UserId
	local data = UserID:GetAsync(UserID)
	
	if data then
		
		SpendingCoins.Value = data
		
	else
		
		SpendingCoins.Value = 0
		
	end
	
end)

game.Players.PlayerRemoving:Connect(function(plr)
	
	local Success, Errors = pcall(function()
		
		local Name = plr.DisplayName
		local SpendingCoins = game.Workspace.Players:FindFirstChild(""..Name).SpendingCoins
		
		local UserID = "Player"..plr.UserId
		PlayerData:SetAsync(UserID, SpendingCoins.Value)
		
	end)
	
	if not Success then
		
		warn("Connection Error, Try Again")
		
	end
	
end)

Please help if you can. Thanks in advance!

3 comments

0

Hello! It looks like there is an error between lines 25-33. Something that I noticed was "game.Workspace.Players". Your issue may be that your instance in the workspace was deleted before or while the removing event fires. Also, I would recommend storing your value inside the player instance (then you can do something like plr.SpendingCoins). Also, try printing Errors to see what's going on.

0

Hello! It looks like there is an error between lines 25-33. Something that I noticed was "game.Workspace.Players". Your issue may be that your instance in the workspace was deleted before or while the removing event fires. Also, I would recommend storing your value inside the player instance (then you can do something like plr.SpendingCoins). Also, try printing Errors to see what's going on.

0

Hello! It looks like there is an error between lines 25-33. Something that I noticed was "game.Workspace.Players". Your issue may be that your instance in the workspace was deleted before or while the removing event fires. Also, I would recommend storing your value inside the player instance (then you can do something like plr.SpendingCoins). Also, try printing Errors to see what's going on.