How to I add a event that happens when a player steps on a block?
✓ ANSWER ACCEPTED
How do I add an event on block touched?
1 answer
✓ Accepted answer
You use the .Touched event.
This code kills the player when they step on the part.
Part.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
Hit.Parent:BreakJoints()
end
end)
Hit is the object that hit the part, we can use an if statement to check to see if the object's parent has a humanoid and if it does then it might be a player, to check if it is a player we can do
Part.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") and game:GetService("Players")[Hit.Parent.Name] then
-- code
end
end)
https://www.robloxdev.com/api-reference/event/BasePart/Touched
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
connect is deprecated, use Connect
sorry is my OCD
Would you be able to post a script where it prints hi when the player touches it?2
just use print("hi") after the if statement