I need this script to work to make my game. Its a script so when a weapon's projectile touches the brick, it lets the projectile pass, but its not 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 (now working thanks to... aews5 and Hybric) end end script.Parent.Touched:connect(onTouch)
Its supposed to do what the quotes say but its not working.
script.Parent, not script.parent
At line 4 AND line 6 "parent" should be "Parent"
it kills the player now, but the projectiles aren't going through the brick.
Hi, I'm TheEliteDonphan
I really don't see anything wrong with your code, but I'm going to re-code it here just in case:
script.Parent.Touched:connect(function(a) -- assuming the script is in the brick local hum = a:findFirstChild"Humanoid" if hum then hum.Health=0 elseif hum == nil then script.Parent.CanCollide = false -- passable wait(3) script.Parent.CanCollide = true -- unpassable end end)
Just so you know, you might have messed up at this part: "elseif"
You have an "if" and an "elseif", but no "else" after elseif??? Change elseif to else if you aren't going to have another condition.