Hello, I'm building an Obby right now and I needed a script to make a spawn change team only one time. Exemple: I succeeded the stage 1 and stepped on the checkpoint(spawn) of the stage 2 and if I try to comeback to the checkpoint of stage 1, I'll not change team because I already passed this stage earlier.
Someone gave me a script for this but there are some problems. When I'm in the spawn of the stage 1 and I go to the spawn of the stage 2 and I die, I'll spawn to the spawn of the stage 3.
Another thing, the script save the last spawn before I disconnected and I don't want it :( . I want when someone disconnect it reset all his progression in the Obby.
Here's the script I put in ServerScriptService:
`local saves = true -- Does it save what level they are on? If so when they join the game they go to their last level. local playerDeadTime = 0.1 -- How long after dying players spawn
local datastore = game:GetService("DataStoreService"):GetDataStore("Stats") game.Players.CharacterAutoLoads = false
game.Players.PlayerAdded:connect(function(player) local level = Instance.new("StringValue",player) if saves then local stored = datastore:GetAsync(player.userId) print(stored) if stored ~= nil then level.Value = stored else level.Value = "Start" end else level.Value = "Start" end level.Name = "SpawnLevel" player.CharacterAdded:connect(function(char) wait() char:MoveTo(workspace:FindFirstChild("Spawn"..level.Value,true) ~= nil and workspace:FindFirstChild("Spawn"..level.Value,true).Position + Vector3.new(0,3,0) or Vector3.new(0,100,0)) char:WaitForChild("Humanoid").Died:connect(function() delay(playerDeadTime,function() player:LoadCharacter() end) end) end) wait(2) player:LoadCharacter() end)
game.Players.PlayerRemoving:connect(function(player) local level = player:FindFirstChild("SpawnLevel") if level then if saves then if datastore:GetAsync(player.userId) ~= nil then datastore:UpdateAsync(player.userId,function(old) return level.Value end) else datastore:SetAsync(player.userId,level.Value) end end end end)
local function spawns() curse = function(p) for _,v in next, p:GetChildren() do if v:IsA("BasePart") then if v.Name:sub(1,5) == "Spawn" then v.Touched:connect(function(hit) if hit and hit.Parent then local human = hit.Parent:FindFirstChild("Humanoid") if human then if human.Health > 0 then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then local level = player:FindFirstChild("SpawnLevel") if level then level.Value = v.Name:sub(6) end end end end end end) end end curse(v) end end curse(workspace) end
spawns()
game.OnClose = function() wait(3) end`
Thanks in advance !