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

Does this kind of function work anymore? (About a door script)

Asked by 4 years ago
Edited 4 years ago

I have used this kind of script before, but I just don't know why it doesn't work anymore. The Transparency is meant to change to 0.5 when it is clicked and 0 when it is clicked again. And I'm not sure if an update changed something, I've been offline for a while. edit The transparency works now but doesn't switch back to zero. I just needed to switch the numbers around.

Here's the code I tried:

local door = script.Parent
local click = script.Parent.ClickDetector
local hoverbox = Instance.new('SelectionBox', door)
hoverbox.Visible = false
local clickdoor = function()
    door.CanCollide = not door.CanCollide
    door.Transparency = not door.Transparency and 0.5 or 0
end
local hoverdoor = function()
    hoverbox.Visible = true
end
local nothoverdoor = function()
    hoverbox.Visible = false
end
click.MouseClick:Connect(clickdoor)
click.MouseHoverEnter:Connect(hoverdoor)
click.MouseHoverLeave:Connect(nothoverdoor)
hoverbox.Adornee = door

The CanCollide setting is correct, however. So I'm wondering if you can't use and 0.5 or 0 anymore.

0
That's not how "and" and "or" are supposed to be used... DeceptiveCaster 3761 — 4y
0
Well it used to work, so I'm thinking that there was an update and you cant do it anymore MuffinZMan_YT 20 — 4y
0
Bash is correct, the "and" and "or" are conditional operators. You'll never be able to have it choose between 0.5 and 0 transparency. You'll definitely need an if statement, that's why it only changes the transparency when you switch the numbers around SteelMettle1 394 — 4y

Answer this question