Recently many players of my game have reported that sometimes when they join they're stage is set at '1' despite them being further in the game.
On other people's screens it normal (the actual stage the person is on.)
I have really no idea how to fix this glitch and so many people ask me about it that it hurts my soul, please help.
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(stage.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)
