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

How do I add an event on block touched?

How to I add a event that happens when a player steps on a block?

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

4 comments

0

connect is deprecated, use Connect

0

sorry is my OCD

0

Would you be able to post a script where it prints hi when the player touches it?2

0

just use print("hi") after the if statement

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