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

Making trap part that set Character health to 0? What did I do wrong?

Hi,

I copy-pasted the exact script from Roblox education site but it doesn't work. The script is in the workspace

local trap = script.Parent

-- Checks for Humanoid in otherPart
local function onTouch(otherPart)
	-- Store parent of otherPart
	local character = otherPart.Parent

	-- Looks for a humanoid
	local humanoid = character:FindFirstChil("Humanoid")

	if humanoid then
		-- If part has humanoid, set health to 0
		humanoid.Health = 0
	end
end

-- Connect the Touched event to onTouch
trap.Touched:Connect(onTouch)

6 comments

0

did you put the code inside the part?

0

Roblox studio doesn't allow script inside a part. It's not possible unless you create a script that is Child of the Part and put your script inside "Script"

0

It is possible . That is what jesse meant when he said to put the code insdie the part.

0

sorry I misinterpreted you to mean putting code inside part without creating a script. Yes I did put it in the part. I used to code for about a month and then stopped. Now I am back at it, but couldn't make a trap part which I previously learned in the first few day of coding

0

sorry i meant to say script inside the part.

0

Change FindFirstChil to FindFirstChild and that will fix your problem

1 answer

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