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

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

Asked by 3 years ago
Edited 3 years ago

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)
0
did you put the code inside the part? JesseSong 3916 — 3y
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" HegemoneXT -45 — 3y
0
It is possible . That is what jesse meant when he said to put the code insdie the part. JustinWe12 723 — 3y
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 HegemoneXT -45 — 3y
View all comments (2 more)
0
sorry i meant to say script inside the part. JesseSong 3916 — 3y
0
Change FindFirstChil to FindFirstChild and that will fix your problem JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Try looking at this model

https://www.roblox.com/library/339702422

Ad

Answer this question