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

How do I add an event on block touched?

Asked by 6 years ago

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

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

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

0
connect is deprecated, use Connect User#19524 175 — 6y
0
sorry is my OCD DaCrazyDev 444 — 6y
0
Would you be able to post a script where it prints hi when the player touches it?2 tightanfall 110 — 6y
0
just use print("hi") after the if statement DaCrazyDev 444 — 6y
Ad

Answer this question