So I have this area system and when you have enough rebirths you can go to the next area and removes the GUI. But right now it removes the GUI but you still get teleported back to spawn.
Here's the script!
script.Parent.Touched:Connect(function(hit) local debounce = false if hit:IsA("BasePart") then if game.Players:FindFirstChild(hit.Parent.Name)["leaderstats"].Rebirths.Value >= 2 then debounce = false else if game.Players:FindFirstChild(hit.Parent.Name)["leaderstats"].Rebirths.Value <= 1 then if hit.Parent:FindFirstChild("Humanoid") then hit.Parent.Head.CFrame = CFrame.new(game.Workspace.SpawnTP.Position) end end end end end)
Ok so here are some of the problems I see: 1. The debounce = false twice doesn't do anything, so i adjusted that portion accordingly. 2. You have else (space) if instead of elseif, so that would be one problem. 3. When moving a character, it is generally better to alter their HumanoidRootPart CFrame position, rather than the Head since the HumanoidRootPart is the PrimaryPart of the Model. 4. You also need to change the CFrame to another CFrame, rather than the CFrame to a Position. With this in mind, I revised your script to the following code in a Server Script (preferably in ServerScriptService):
local debounce = false script.Parent.Touched:Connect(function(hit) if debounce == true then return end debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent) local rebirth = player["leaderstats"].Rebirths.Value if rebirth >= 2 then hit.Parent.HumanoidRootPart.CFrame = workspace.SpawnTP2.CFrame elseif rebirth <= 1 then hit.Parent.HumanoidRootPart.CFrame = workspace.SpawnTP.CFrame end debounce = false end)
I chose the name "SpawnTP2" since obviously the spawn cannot be the same for both. If you need an offset for the CFrames, you can do the following:
hit.Parent.HumanoidRootPart.CFrame = game.Workspace.SpawnTP.CFrame + Vector3.new(0, 0, 0)
EDIT: 5. Removed CFrame.new(), Removed redundant Humanoid checks