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

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

Asked by
anerth 25
10 years ago

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

Log in to vote
0
Answered by
aews5 15
10 years ago

script.Parent, not script.parent

0
it kills the player now, but the projectiles aren't going through the brick. anerth 25 — 10y
Ad
Log in to vote
0
Answered by
Hybric 271 Moderation Voter
10 years ago

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

0
it kills the player now, but the projectiles aren't going through the brick. anerth 25 — 10y
Log in to vote
0
Answered by
anerth 25
10 years ago

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

Log in to vote
0
Answered by
aalok 20
10 years ago

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)
Log in to vote
0
Answered by
c0des 207 Moderation Voter
10 years ago

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.

0
elseif is basically an else and if combined. instead of going else then on the next line if, it only takes 1 line. anerth 25 — 10y

Answer this question