I've created a part that when it gets touched it returns the player to a spawnpoint but when a player touches it every player in the game gets teleported even though its a local script! How is this possible?
local Teams = game:GetService("Teams") local barrier = game.Workspace.Barrier local player = game.Players.LocalPlayer barrier.Touched:connect(function() local char = player.Character local humanoid = char:WaitForChild("Humanoid") local humanoidroot = char:WaitForChild("HumanoidRootPart") if player.Team.Name == "Stage1" and humanoid.Health ~= 0 then humanoidroot.Anchored = true char:MoveTo(game.Workspace.Spawns.Checkpoint1.Position) wait() humanoidroot.Anchored = false end end)
By the way, if I put the character variable outside the function it doesn't work after the player resets because it using the old character which I don't know how to fix.
Ah, I figured it out. Your script executes the function when whatever player touches it. You need to add a check.
Try this
local Teams = game:GetService("Teams") local barrier = game.Workspace.Barrier local player = game.Players.LocalPlayer barrier.Touched:connect(function(hit) if hit.Parent.Name == player.Name then local char = player.Character local humanoid = char:WaitForChild("Humanoid") local humanoidroot = char:WaitForChild("HumanoidRootPart") if player.Team.Name == "Stage1" and humanoid.Health ~= 0 then humanoidroot.Anchored = true char:MoveTo(game.Workspace.Spawns.Checkpoint1.Position) wait() humanoidroot.Anchored = false end end end)
(Sorry if the formatting isn't the best)