I have these billboardguis that I make bounce up and down and when the player gets near it I cancel the tween and make it stationary and when they walk away the tween resumes, however, it’s now desync from the rest. I’d like all of them to always be tweening at the same time.
This is the code for it. Every object has a loop that just plays the tweens I know it’s not the most effective, but it works for now.
function MenuObject.new(menuID,triggerPart,billboardGui)
local self = setmetatable({},MenuObject)
self.menuID = menuID
self.triggerPart = triggerPart
self.billboardGui = billboardGui
self.currentTween = nil
self.near = false
self.downTween = TweenService:Create(billboardGui,info1,goals1)
self.upTween = TweenService:Create(billboardGui,info2,goals2)
self.command = OpenMenuCommand.new(menuID)
--TODO: Clean this up
task.spawn(function()
while true do
task.wait()
if self.near then continue end
self.currentTween = self.downTween
self.currentTween:Play()
task.wait(.3)
self.currentTween = self.upTween
self.currentTween:Play()
task.wait(1)
end
end)
return self
end
-- function to run when plyer is near
function MenuObject:triggerEntered()
self.near = true
self.currentTween:Cancel()
self.billboardGui.StudsOffset = Vector3.new(0,0,0)
self.billboardGui.Text.Visible = true
end
-- function to call when player is no longer near
function MenuObject:triggerExited()
self.near = false
self.billboardGui.Text.Visible = false
end