local rs = game:GetService("ReplicatedStorage")
local Update = rs:WaitForChild("UpdateGui")
local WinUpdater = rs:WaitForChild("WinsUpdater")
local DataStoreService = game:GetService("DataStoreService")
local DataStore1 = DataStoreService:GetDataStore("DataStore1")
local function ClientFire(wins)
print("super happy")
Update:FireAllClients(wins)
end
local function onPlayerJoin(player)
local wins = Instance.new("IntValue")
wins.Name = "wins"
wins.Value = 0
wins.Parent = player
local ID = player.UserId
local data
local s, em = pcall(function()
return DataStore1:GetAsync(ID, data)
end)
if s then
print("got data!")
wins.Value = data
else
warn(em)
end
ClientFire(wins.Value)
end
game.Players.PlayerRemoving:Connect(function(player)
local ID = "Player_"..player.UserId
local data = player.wins.Value
local s, em = pcall(function()
DataStore1:SetAsync(ID,data)
end)
if s then
print("saved!" .. data)
else
print("sad")
warn(em)
end
end)
game.Players.PlayerAdded:Connect(onPlayerJoin)
WinUpdater.Event:Connect(function(tp, plr)
print("very happy")
local wins = plr:WaitForChild("wins").Value
if tp == 1 then
wins = wins + 2
else if tp == 2 then
wins = wins + 1
end
end
ClientFire(wins)
end)
This is my script, it runs through everything completely fine but once it prints "saved" .. data, it always saves as zero even though I changed the values, I also update it manually in the test on the server yet it still doesn't save. I think it might just be an easy mistake but I can't figure it out, can someone help me? (tp = totalplayers)
