Pretty simple but I'm not sure how to fix. Whenever I touch a checkpoint in my game, it takes a while to put the stat in the leaderboard. Script:
local datastore = game:GetService("DataStoreService"):GetDataStore("GameStore")
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("IntValue") leaderstats.Name = "leaderstats" leaderstats.Parent = player
local level = Instance.new("IntValue")
level.Name = "Stage"
level.Parent = leaderstats
level.Value = 1
local key = "user-" .. player.userId
local storeditems = datastore:GetAsync(key)
if storeditems then
level.Value = storeditems[1]
else
local items = {level.Value}
datastore:SetAsync(key, items)
end
local spawn = game.Workspace:WaitForChild(player.leaderstats.Stage.Value)
if player and spawn then
player.Character:MoveTo(spawn.Position + Vector3.new(0, 3, 0))
end
end)
game.Players.PlayerRemoving:connect(function(player) local items = {player.leaderstats.Stage.Value} local key = "user-" .. player.userId datastore:SetAsync(key, items) end)
game.Workspace.ChildAdded:connect(function(obj) local player = game.Players:GetPlayerFromCharacter(obj) if player then local leaderstats = player:FindFirstChild("leaderstats") local stage = leaderstats:FindFirstChild("Stage") local respawn = game.Workspace:WaitForChild(level.Value) obj.Torso.CFrame = obj.Torso.CFrame + Vector3.new(0,3,0) wait(0.1) obj.Torso.CFrame = respawn.CFrame + Vector3.new(0,3,0) end end)

1 comment
Can you fix the script?