I made a data saving and for some reason after it gives data to somebody else after anyone rejoins I don’t understand why it’s happening here’s my script
can call be causing this?
local ds = game:GetService("DataStoreService")
local CashDataStore = ds:GetOrderedDataStore("Cash")
game.Players.PlayerAdded:Connect(function(player)
if player.UserId >= 0 then
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Value = 0
Cash.Parent = leaderstats
local datapiece
local Sucess,Error = pcall(function()
datapiece = nil
datapiece = CashDataStore:GetAsync(player.UserId)
Cash.Value = datapiece
if datapiece then
player.StarterGui.MoneyGui.TextLabel = Cash.Value
print("Found Data Applying")
else
print("First time playing maybe?")
end
end)
if Sucess then
print("Sucess")
else
print(Error)
end
game.Players.PlayerRemoving:Connect(function(player)
local datapiece
local Sucess,Error = pcall(function()
datapiece = nil
datapiece = CashDataStore:SetAsync(player.UserId,Cash.Value)
end)
if Sucess then
print("Saved Data")
else
print(Error)
end
end)
end
end)