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

I have a problem,how you make a traps?

this is my awnser

local trapPart = script.Parent
local function onPartTouch(otherPart)
    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if ( humanoid ) then
        humanoid.Health = 0
    end
end
trapPart.Touched:Connect(onPartTouch)

5 comments

0

how you makes traps alot better?

0

I don't see anything wrong with this, it's a simple script that seems to work.

0

ik! how you makes a traps better.

0

What do you mean by that? Better how?

0

well! i am very new to scripting

1 answer

✓ Accepted answer

I will explain below how the code works. What I believe you're trying to accomplish is that when a player walks on a part (trapPart), then the script checks if the object that touched itself is a humanoid, and if so, it will change the humanoid of the character to zero health.

local trapPart = script.Parent --parent of script
trapPart.Touched:Connect(function(object) --object is what touched trapPart
	if object.Parent:FindFirstChild("Humanoid") then --checks if there is a humanoid
		object.Parent.Humanoid.Health = 0 --set humanoid's health
	end
end)

That should be what you are trying to accomplish. Otherwise, you are doing pretty good for a starter. Keep it up!

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