Hello I'm making a turret with an Idle rotation. I'm happy to say it works... Well so-so.
Here is my code:
local TurretHead = script.Parent.Parent:FindFirstChild("TurretHead")
local function Rotation(Direction)
if Direction == "Right" then
repeat wait()
TurretHead:SetPrimaryPartCFrame(TurretHead.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(.01,0,0))
until TurretHead.Spin.Orientation.Y >= 45
elseif Direction == "Left" then
repeat wait()
TurretHead:SetPrimaryPartCFrame(TurretHead.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(-.01,0,0))
until TurretHead.Spin.Orientation.Y >= -45
end
end
local Toggle = false
while true do wait()
Toggle = not Toggle
if Toggle == false then
print("Left")
Rotation("Left")
elseif Toggle == true then
print("Right")
Rotation("Right")
end
end
As you can see under the function i have added a repeat until loop but the problem is the turret will go to 180 degrees then switch to next rotation and it still goes to 180 degrees even if i change the numbers. I do not see the problem with the code but eventually there is...
If anyone can see the issue please let me know. Thanks
