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 (Thanks to chimmihc) 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. EDIT: I resolved the problem that I put in bold. I need to give every spawn's name a different one but this script don't match with what I want because I can comeback to every spawn that I passed.
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 !
This is a part-answer, you said you didn't want their progress to save when they disconnect, the first line of the script says this:
local saves = true -- Does it save what level they are on? If so when they join the game they go to their last level.
Have you tried putting that to false?
Problem resolved
If someone wanna know my code:
Team1 = "Team Color Here" Team2 = "Team Color Here" script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local Player = game.Players:GetPlayerFromCharacter(hit.Parent) if Player.TeamColor == BrickColor.new(Team1) then --If you're in this team, he detect you Player.TeamColor = BrickColor.new(Team2) --To change your team in this team end end end)
You need also to place a transparent part that you uncheck CanCollide on the SpawnLocation with the same scale (Uncheck AllowTeamChangeOnTouch also)
Put the script in that transparent part.