Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Touched runs for all players even when it's in a local script?

I have a teleporting script and a part that detects if it got touched by a player and teleports the player that touched it. But it's not working as it's supposed to. It's teleporting ALL players. Even players that hasn't even touched it.

The script looks something like this but it's not the real script.

part.Touched:Connect(function(p)
	
	local plr = game.Players:GetPlayerFromCharacter(p.Parent)
	
	if plr ~= nil then
	player.Character.Humanoid.Torso.CFrame = CFrame.new(206.25, -159.5, -1833)
	end
	
end)

5 comments

0

We cannot answer a question if you do not give us the full script, also I don't think touched works in a local script and it sure doesn't work if it's inside the workspace and a local script

0

There isn't much to the script other than this part.

1

you don't have the 'teleport' code? thats where the problem occurs.

1

Ok I added the teleport code.

1

ok try my answer out

1 answer

✓ Accepted answer
part.Touched:connect(function(hit)
	if hit then 
		if hit.Parent:FindFirstChild('Humanoid') and game.Players:FindFirstChild(hit.Parent.Name) then 
			local player = game.Players:FindFirstChild(hit.Parent.Name)
			player.Character.HumanoidRootPart.CFrame = CFrame.new(206.25, -159.5, -1833) -- paste the position you want the player to teleport to here
		end
	end
end)

4 comments

1

.

1

hope this works, accept it if it does

1

Thank you!!!!!! This works perfectly and only teleports the player that touched the part.

1

:D np

This discussion is preserved as it was. New answers, comments, and votes are closed.