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

How do I make this script for a walk-throughable brick when a part touches it work?

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.

5 answers

script.Parent, not script.parent

1 comment

0

it kills the player now, but the projectiles aren't going through the brick.

At line 4 AND line 6 "parent" should be "Parent"

1 comment

0

it kills the player now, but the projectiles aren't going through the brick.

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.

1 comment

0

elseif is basically an else and if combined. instead of going else then on the next line if, it only takes 1 line.

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