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

How to make a ClickDetector's RemoteEvent function reversible? (Sovled)

Asked by 5 years ago
Edited 5 years ago

I have fashioned a cover that has a click detector in it. When clicked, the cover rises with a remote event function changing it's orientation and position, as shown below.

game.Workspace.ButtonCoverEvent2.OnServerEvent:Connect (function() game.Workspace.ButtonCover2.Orientation = Vector3.new (90,-90,0) game.Workspace.ButtonCover2.Position = Vector3.new (-70.02, 9.611, 18.6) end)

My question is, how do I code the function so that when the click detector is clicked again, the cover returns to it's original position/orientation?

0
You can make a boolean variable that identifies whether to reverse it or not. If you want it reversed, just do the entire motion backwards. GiveMeYourPudding 64 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

What you looking for is a bool that changes every time the button is clicked. This allows you to keep track of whether the door should be opened or closed. Assuming the door starts closed, the following code would work:

local isOpen = false --Not opened yet
local button = game.Workspace:WaitForChild("ButtonCover2")
local startPos = button.Position
local startOrien = button.Orientation
game.Workspace.ButtonCoverEvent2.OnServerEvent:Connect (function()
    isOpen = not isOpen --Reverse the bool
    if isOpen then--Open
        button.Orientation = Vector3.new (90,-90,0)
        button.Position = Vector3.new (-70.02, 9.611, 18.6)
    else--Close
        button.Orientation = startOrien
        button.Position = startPos
    end
end)

Hope I could help, if I did, mark this correct, if not, comment what the problem is and I can help you fix it. Otherwise, have a great day! -REALTimothy0812

Ad

Answer this question