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.

5 comments
Thank you so much it actually worked! I quess it was simpler than I tought.
No problem! Don't forget to mark my answer as correct too :)
how?
There should be a button below or above the answer.
nevermind the button wasn't showing but i fixed it