Need help with script

I want to have the flash light turn 45 degrees to the left but only that.
The main problem is, its that whenever you hover over the GUI it causes it to turn every time meaning the flashlight can go behind the player. I only want it to turn that once and be locked there.

	workspace.campart.FlashLight.CFrame = workspace.campart.FlashLight.CFrame * CFrame.Angles(0,45,0)

EDIT: So basically i want to check if the cframe is already rotated by 45 degrees and if it is then i do not want it to turn anymore.

You can create a debounce.

Here’s an example:

local debounce = false
if not debounce then
   debounce = true
	workspace.campart.FlashLight.CFrame = workspace.campart.FlashLight.CFrame * CFrame.Angles(0,45,0)

It works but then when i hover over the gui again after it doesnt work again, I want it to lock so it cannot go past 45 on both sides so 45 and -45 is where i want them locked so they can go anywhere inbetween those numbers but not anywhere after them, Does that make more sense?

Ok I think I get it. To make it work after do:

   debounce = false

This will basically reset the debounce to false. Hopefully this helps.

How would i go about comparing them?

Can you provide the full script? I assume there’s a button which rotates the flashlight negative 45 degrees around the Z-axis.

I’ll just provide an example instead, it should be fairly simple to follow.

local left = false
local right = false

	if left then
	left = true
	right = false
	--rotate -45 degrees

	if right then
	right = true
	left = false
	--rotate +45 degrees

Well if that’s the case than try this :

local defaultCF

local executionAmount = 0
	executionAmount += 1
	if executionAmount == 1 then
		workspace.campart.FlashLight.CFrame = workspace.campart.FlashLight.CFrame * CFrame.Angles(0,45,0)
		defaultCF = workspace.campart.FlashLight.CFrame
		workspace.campart.FlashLight.CFrame = defaultCF

Here I am checking if its the first time your rotating it or not, if it is than Im storing the new CFrame so that if you click again it will stay the same and won’t rotate furthermore.

THANK YOU SO MUCH, I am very grateful, I combined the default cframe idea from your script with the script above thank you guys so much

1 Like

You’re very welcome. If you need help with anything else don’t hesitate to ask me!!