why sometimes when i join the game i will spawn at the spawn point not my stage
or sometimes i die i will go back to spawn point
this is the saving script:
local players = game:GetService(“Players”)
local dataStoreService = game:GetService(“DataStoreService”)
local saveDataStore = dataStoreService:GetDataStore(“SaveData”)
local max = 300
local function savePlrData(plr)
local success,err = pcall(function()
local saveData = {}
for _,stat in pairs(plr.leaderstats:GetChildren()) do
saveData[stat.Name] = stat.Value
end
saveDataStore:SetAsync(plr.UserId,saveData)
end)
if not success then return err end
end
players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Parent = stats
stage.Value = 1
local rebirths = Instance.new("IntValue")
rebirths.Name = "Rebirths"
rebirths.Parent =stats
local data = saveDataStore:GetAsync(plr.UserId)
if data then
print(data.Stage)
for _,stat in pairs(stats:GetChildren()) do
stat.Value = data[stat.Name]
end
else
print(plr.Name .. " has no data")
end
plr.CharacterAdded:Connect(function(char)
local humanoid,hrp = char:WaitForChild("Humanoid"),char:WaitForChild("HumanoidRootPart")
wait()
if humanoid and hrp then
if stage.Value ~= 0 then
local part = workspace.ObbyStages:FindFirstChild(stage.Value)
hrp.CFrame = part.CFrame + Vector3.new(0,1,0)
end
end
end)
end)
game.ReplicatedStorage.Rebirths.OnServerEvent:Connect(function(player)
local stage = player.leaderstats.Stage.Value
if tonumber(stage) >= max then
player.leaderstats.Stage.Value = 1
player.leaderstats.Rebirths.Value = player.leaderstats.Rebirths.Value + 1
game.ReplicatedStorage.Rebirths:FireClient(player)
end
end)
players.PlayerRemoving:Connect(function(plr)
local err = savePlrData(plr)
if err then print(err) end
end)
game:BindToClose(function()
for _,plr in pairs(players:GetPlayers()) do
local err = savePlrData(plr)
if err then print(err) end
end
wait(2)
end)
and this is the stage handler:
local obbyStages = workspace:WaitForChild(“ObbyStages”)
for _,stage in pairs(obbyStages:GetChildren()) do
stage.Touched:Connect(function(hit)
local hum
if hit.Parent:FindFirstChild("Humanoid") then
hum = hit.Parent.Humanoid
end
if hit.Parent and hit.Parent.Parent:FindFirstChild("Humanoid") then
hum = hit.Parent.Parent.Humanoid
end
if hum then
local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
local plrStage = plr.leaderstats.Stage.Value
if tonumber(stage.Name) == plrStage + 1 then
plr.leaderstats.Stage.Value = plr.leaderstats.Stage.Value + 1
elseif tonumber(stage.Name) > plrStage + 1 then
hum.Health = 0
end
end
end)
end
this is the game:
https://www.roblox.com/games/4691373457/Extreme-Parkour-Stage-locator?refPageId=6b14f600-3085-4cfa-9641-f433405f3a60