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

How does the Touched event work again?

I somehow forgot how to write a line of code for touching a brick to trigger something. Right now i have this:

script.Parent.Touched:Connect(function(player) game:GetService("TeleportService"):Teleport(3299820826) end)

The end) is messed up by the string.

So I mainly just need an explanation. A working script would be fine as well.

1 answer

✓ Accepted answer

To get the player from a touch event you need to first check if the thing who touched the part is a player then you can use :GetPlayerFromCharacter to get the player from hit.Parent.

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
game:GetService("TeleportService"):Teleport(3299820826,Player)
end
end)

2 comments

0

thanks

0

np

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