I'm learning to code from a tutorial book and i followed all the instructions but its not doing what i thought it should. Can anyone help me to understand where i went wrong?

local Door = script.Parent--I have declared the part as Door.
function onTouch(Brick)--Sets the start of our function and when triggered it gives back, the object that was hit.
local Player = Brick.Parent:findFirstChild("Humanoid")--Finds Humanoid in Brick.
if(Player~=nil)then--Checks if Player is a real Player.
if Player.Parent.Torso.roblox.Texture == "http://www.roblox.com/asset/?id=382538058" then
Door.CanCollide = false--Our door is no longer solid.
Door.Transparency = 0.5--Our door is now partially transparent.
Door.BrickColor = BrickColor:Random()--We have assigned a randomly color to the door.
wait(2)--Wait 2 seconds.
Door.CanCollide = true--Our door is now solid.
Door.Transparency = 0--Our door is non-transparent
Door.BrickColor = BrickColor:Random()--We have assigned another randomly generated color to our door.
else Player.Health = 0--Deny access and Kill the Character.
end
end
end
Door.Touched:connect(onTouch)--Our door is now connected the the function onTouch().

1 comment

1

Don't come on this site with code that isn't yours, expecting for it to be fixed. Do not learn from YouTube or whatever you are learning from.