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

Why is my door not happy with this if statement?

I am trying to create a door that will open and close upon being clicked. To stop the door opening/closing parts from being able to appear at the same time, I used an if statement.

function OnClick()
	if script.Parent.Parent.Door1.Transparency == 1 then
		script.Parent.CanCollide = false
		script.Parent.Parent.Door2.Transpareny = 1
		script.Parent.Parent.Door1.Transparency = 0
    end
end

The scripts are the door's children. I've done this for both doors. They use a seperate script. One script ignores the if statement and proceeds to make itself non-transparent, and the Other responds with "Transparency is not a valid member of UnionOperation"

Without the if statement, they will work, but can be activated at the same time. I know it is a very simple script, but it is a little hurdle I am struggling to overcome. Any help would be appreciated.

EDIT: All and solved. Thanks for letting me know the issues and the alternatives!

1 comment

0

And if the door is a model or union then the script will not work since transparency and Can collide isn't a valid member of a model object

2 answers

Its not gonna run since nothing put the transparency to 1 so try using this script

local part = script.Parent
part.MouseButton1Click:connect(function())
part.Transparency == 1
part.CanCollide = false
wait(1)-- how many seconds you want the door to stay opened
part.CanCollide = false
part.Transparency == 0
end)

4 comments

0

Make sure to put this inside of the door object, and accept my answer if it works.

0

Somemany mistakes

0

Mousebutton1click is only for guis and you didnt reference the player that has joined the game.

0

Oh thanks for the correction

Make sure you are using locals before your variables and calling them by using the operator ()

-- The door 'BasePart'
local door = script.Parent
-- Create a ClickDetector
local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = door
ClickDetector.MaxActivationDistance = 10
ClickDetector.CursorIcon = "rbxassetid://"..CursorId
 
-- Make door slightly transparent when mouse hovers over it
ClickDetector.MouseHoverEnter:Connect(function()
	door.Transparency = 0.1
end)
 
-- Door is not transparent when mouse is not hovering over it
ClickDetector.MouseHoverLeave:Connect(function()
	door.Transparency = 0
end)
 
-- Open door on left mouse click
ClickDetector.MouseClick:Connect(function()
	door.Transparency = 0.8
	door.CanCollide = false
end)
 
-- Close door on right mouse click
ClickDetector.RightMouseClick:Connect(function()
	door.Transparency = 0.1
	door.CanCollide = true
end)

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