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.
local debounce = false
script.Parent.MouseEnter:Connect(function()
if not debounce then
debounce = true
workspace.campart.FlashLight.CFrame = workspace.campart.FlashLight.CFrame * CFrame.Angles(0,45,0)
end)
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?
I’ll just provide an example instead, it should be fairly simple to follow.
local left = false
local right = false
buttonLeft.MouseEnter:Connect(function()
if left then
return
end
left = true
right = false
--rotate -45 degrees
end)
buttonRight.MouseEnter:Connect(function()
if right then
return
end
right = true
left = false
--rotate +45 degrees
end)
local defaultCF
local executionAmount = 0
script.Parent.MouseEnter:Connect(function()
executionAmount += 1
if executionAmount == 1 then
workspace.campart.FlashLight.CFrame = workspace.campart.FlashLight.CFrame * CFrame.Angles(0,45,0)
defaultCF = workspace.campart.FlashLight.CFrame
else
workspace.campart.FlashLight.CFrame = defaultCF
end
end)
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.