Same case, it still spinned the compass
Itβs a bit sloppy but,
local plr = script.Parent.Parent.Parent.Name
local TweenService = game:GetService("TweenService")
local ang = 0
local tween;
while wait() do
local look = game.Workspace.Camera.CFrame.LookVector
local angle = math.atan2(look.X, look.Z)
ang = math.deg(angle) % 360 -- also try -(math.deg(angle) % 360)
local goal = {}
goal.Rotation = ang
local tweenInfo = TweenInfo.new(0.6)
if script.Parent.ImageLabel.Rotation >= 270 and goal.Rotation <= 90 then
if tween then
tween:Cancel()
end
script.Parent.ImageLabel.Rotation = 0
tween = TweenService:Create(script.Parent.ImageLabel, tweenInfo, goal)
tween:Play()
elseif script.Parent.ImageLabel.Rotation <= 90 and goal.Rotation >= 270 then
if tween then
tween:Cancel()
end
script.Parent.ImageLabel.Rotation = 360
tween = TweenService:Create(script.Parent.ImageLabel, tweenInfo, goal)
tween:Play()
else
if tween then
tween:Cancel()
end
tween = TweenService:Create(script.Parent.ImageLabel, tweenInfo, goal)
tween:Play()
end
script.Parent.TextLabel.Text = ang
end
This works but it snaps. I tried making it tween to 359.99 then setting the rotation to 0, then proceeding the tween but it seems to not work. Do what you can with the script
After a while, I just figured out how to fix the spinning compass after it reaches 360 degrees.
Here is the updated script for those who are curious about how I fixed it.
local plr = script.Parent.Parent.Parent.Name
local TweenService = game:GetService("TweenService")
local ang = 0
local previousAngle = 0
local current
local prevAngle = 0
local AddTo
while wait() do
local look = game.Workspace.Camera.CFrame.LookVector
local angle = math.atan2(look.X, look.Z)
if angle ~= previousAngle then
local Degrees = script.Parent.Degrees
previousAngle = angle
ang = -math.deg(angle) % 360
current = ang
AddTo = current - prevAngle
if AddTo <= -100 then
AddTo = AddTo / -100
end
if AddTo >= 300 then
AddTo = AddTo / 100
end
Degrees.Value = Degrees.Value + AddTo
prevAngle = ang
local goal = {}
goal.Rotation = Degrees.Value
local tweenInfo = TweenInfo.new(0.6)
local tween = TweenService:Create(script.Parent.ImageLabel, tweenInfo, goal)
tween:Play()
script.Parent.TextLabel.Text = math.floor(ang)
end
end
Thanks to those who replied.
1 Like