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

Why Isn't my part not setting people on fire?

Asked by 2 years ago

So Im making a tool that whenever a humanoid touches the tool's handle (Or part) It well set them to fire. However It for some reason doesn't set It on fire

Here Is the script (NOTE: This script Is added Inside of the handle Itself)

script.Parent.Touched:Connect(function(Hit)
    if Hit.Parent:WaitForChild("Humanoid") then
        local char = Hit.Parent
        local fire = Instance.new("Fire")
        fire.Position = char.HumanoidRootPart
    end
end)

2 answers

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

You should probably use findFirstChild() instead of waitForChild() because if the part that touches it will never have a humanoid, it will just keep waiting for one that will never be there. Also, when you use Instance.new() with only one argument, the new instance does not have a parent yet. You can use the 2nd argument of Instance.new() which lets you decide what the fire's parent will be. Lastly, Position isn't a property of fire, if I were you, I'd just make the fire a child of the humanoidRootPart:

script.Parent.Touched:Connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") then
        local char=Hit.Parent.HumanoidRootPart
        local fire = Instance.new("Fire",char)
    end
end)
0
Thanks! imnotaguest1121 362 — 2y
0
No problem! boqueburro 57 — 2y
Ad
Log in to vote
0
Answered by
bailley5 114
2 years ago
Edited 2 years ago

To find whether hit.Parent has a humanoid, you use FindFirstChild()

script.Parent.Touched:Connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") then
        local char = Hit.Parent
        local fire = Instance.new("Fire")
        fire.Position = char.HumanoidRootPart
    end
end)

Answer this question