Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How does the Touched event work again?

Asked by 4 years ago

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

Log in to vote
0
Answered by
Prestory 1395 Moderation Voter
4 years ago
Edited 4 years ago

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)
0
thanks zboi082007 270 — 4y
0
np Prestory 1395 — 4y
Ad

Answer this question