Keep getting this error on a tweening line when player dies. Don’t get errors any other time I tween, only on this line
Error on the tweening line
[Bar]
[15:42:13.470 - Can only tween objects in the workspace]
local function updateData(data)
Coins.Text = data.Coins
CurrentLevel.Text = data.Level
ExpBack.Text = data.Exp .. ' / ' .. data.ExpNeeded
ExpFront.Text = ExpBack.Text
print(Bar) -- Returns the Bar frame
if Bar then
Bar:TweenSize(UDim2.new(data.Exp / data.ExpNeeded, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.25, true)
end
end
DataUpdated.OnClientEvent:Connect(updateData)
DataUpdated:FireServer()
if Bar then
Bar:TweenSize(UDim2.new(data.Exp / data.ExpNeeded, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.25, true)
end
to:
if Bar and Bar.Parent then
Bar:TweenSize(UDim2.new(data.Exp / data.ExpNeeded, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.25, true)
end
That’s why TweenService is better than these weird GuiObject methods. Tweens will not present this kind of error as they are halted and cleared when no longer required or the associated instance is gone. As for GuiObject tweens, the tween attempts to continue running even after the instance is removed.