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

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

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?

1 comment

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.

1 answer

✓ Accepted answer

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

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