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

Why cant we put the click button code in front but behind?

Asked by 4 years ago
Door = game.Workspace.Wall

function pie()
    if Door.Transparency == 1 then
        Door.Transparency = 0
    else
        Door.Transparency = 1
    end
end

script.Parent.ClickDetector.MouseClick:Connect(pie)

"script.Parent.ClickDetector.MouseClick:Connect(pie)"

Why cant we put it in front? v(Like that?)v

Door = game.Workspace.Wall

script.Parent.ClickDetector.MouseClick:connect(function()
    if Door.Transparency == 1 then
        Door.Transparency = 0
    else
        Door.Transparency = 1
    end
end
0
Maybe you forgot the player parameter? 123nabilben123 499 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Your going in the right direction, you can put it INFRONT. BUT I know why your code didn't work.. When you're putting the Event & function in front (basically the same as saying when you're putting script.Parent.ClickDetector.MouseClick:Connect() in front so don't get confused) You forgot to add something, very small, a very small mistake. Make sure to put the script inside the door and put the clickdetector in the door which I think you already had and the script will work! :D

The small mistake you forgot to add was "end)" with the one bracket on the end. It's like that when you put the Event & function in front

local Door = script.Parent 
local cooldown =  2 -- how many seconds till they can click it again to avoid spamming the door
local e = true
script.Parent.ClickDetector.MouseClick:connect(function()
    if Door.Transparency == 1 and e == true then
        e = false
        Door.Transparency = 0
        wait(cooldown)
        e = true
    elseif Door.Transparency == 0 and e == true then
        e = false
        Door.Transparency = 1 
        wait(cooldown)
        e = true
    end
end) -- that small mistake you forgot to add, I replaced "end" to "end)"
Ad

Answer this question