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

Why is this wall script not working?

Asked by
anerth 25
10 years ago

It's supposed to make a weapon's projectile go through the brick, but it isn't working.

function onTouch(part) 
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid == nil) then -- if there is no humanoid in the thing that's touching it...
    script.Parent.CanCollide  =  false -- make the brick passable, or go-through (not working)
    wait(3) --wait 3 seconds
script.Parent.CanCollide  =  true -- make the brick into a full brick again  (not working)
elseif --  or if
 (humanoid ~= nil) then -- a humanoid exists, then
humanoid.Health = 0 -- kill the player 
end
end
script.Parent.Touched:connect(onTouch)

1 answer

Log in to vote
0
Answered by
wrenzh 65
10 years ago

Try this instead (explanation below):

function onTouch(part) 
    if part.Parent:findFirstChild("Humanoid") ~= nil then
        humanoid = part.Parent:findFirstChild("Humanoid")
        humanoid.Health = 0
    else
        script.Parent.CanCollide = false
        wait(3)
        script.Parent.CanCollide = true
    end
end

script.Parent.Touched:connect(onTouch)

The problem I found was that you were defining a variable for something that you did not know existed within that Model, so I rewrote the script a bit.

0
Actually, it still isn't working. The brick is not going Dis-collideable. anerth 25 — 10y
0
The problem might be that the projectile is moving too fast. wrenzh 65 — 10y
0
well, it works once, then when the wall Can Collide it doesn't let my projectile pass through again. anerth 25 — 10y
0
There is a wait(3) in there. Are you waiting for at least 3 seconds? wrenzh 65 — 10y
0
it doesn't let my projectile pass ever again. anerth 25 — 10y
Ad

Answer this question