InputEnded running multiple times?!

I am making a placement system

The rotation gets messed up when i leave the building UI

cant find any solutions

			UIS.InputEnded:Connect(function(input)
				if input.KeyCode == Enum.KeyCode.R then
					--rKeyIsPressed = true
					if placingStructure == true then
						yOrientation = yOrientation + 22.5
						print(yOrientation)
					end
					
				end
			end)

When you look in the output in the video you can see the rotation starts off normal but then it starts firing multiple times…

very weird, pls help

Are you connecting a new callback function to the InputEnded event every time the user selects an item to build? (does the code above run each time the user selects an item from the menu, without getting disconnected?)

1 Like

“does the code above run each time the user selects an item from the menu, without getting disconnected?”

yes, that is correct

Each time it runs, you’re essentially running the same specified function multiple times, causing the rotation added to stack increasingly.

You could either define just one event connection and use an if statement to determine if rotation should be applied, or you could disconnect the existing connection when ever the user is done building something.

local eventConnection = uis.InputEnded:Connect(function() print'example' end)

eventConnection:Disconnect() --//will no longer invoke the function specified in the connect call
1 Like