Can only tween objects in the workspace

I don’t know why the error Can only twin objects in the workspace occurs on page 60.

local tweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)

local damageForColours = {
	[5] = Color3.fromRGB(230, 0, 0),
	[25] = Color3.fromRGB(230, 0, 0),
	[50] = Color3.fromRGB(230, 0, 0),
	[100] = Color3.fromRGB(230, 0, 0),
}

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local humanoid = char:WaitForChild("Humanoid")
		local currentHealth = humanoid.Health

		humanoid.HealthChanged:Connect(function(health)

			if health < currentHealth and humanoid:GetState() ~= Enum.HumanoidStateType.Dead then

				local healthLost = math.floor(currentHealth - health)


				local damageIndicatorGui = Instance.new("BillboardGui")
				damageIndicatorGui.AlwaysOnTop = true

				damageIndicatorGui.Size = UDim2.new(1.5, 0, 1.5, 0)

				local offsetX = math.random(-10, 10)/10
				local offsetY = math.random(-10, 10)/10
				local offsetZ = math.random(-10, 10)/10
				damageIndicatorGui.StudsOffset = Vector3.new(offsetX, offsetY, offsetZ)

				local damageIndicatorLabel = Instance.new("TextLabel")

				damageIndicatorLabel.AnchorPoint = Vector2.new(0.5, 0.5)
				damageIndicatorLabel.Position = UDim2.new(0.5, 0, 0.5, 0)

				damageIndicatorLabel.TextScaled = true
				damageIndicatorLabel.BackgroundTransparency = 1
				damageIndicatorLabel.Font = Enum.Font.FredokaOne

				damageIndicatorLabel.Text = healthLost

				damageIndicatorLabel.Size = UDim2.new(0, 0, 0, 0)

				for damage, colour in pairs(damageForColours) do

					if healthLost <= damage then 			
						damageIndicatorLabel.TextColor3 = colour
						damage = 100
					end
				end

				damageIndicatorLabel.Parent = damageIndicatorGui

				damageIndicatorGui.Parent = char:FindFirstChild("HumanoidRootPart")

				damageIndicatorLabel:TweenSize(UDim2.new(1, 0, 1, 0),
					Enum.EasingDirection.In,
					Enum.EasingStyle.Sine,
					0.3,
					true
				)

				wait(0.3)

				local guiUpTween = tweenService:Create(damageIndicatorGui, tweenInfo, {StudsOffset = damageIndicatorGui.StudsOffset + Vector3.new(0, 1, 0)})
				local textFadeTween = tweenService:Create(damageIndicatorLabel, tweenInfo, {TextTransparency = 1})

				guiUpTween:Play()
				textFadeTween:Play()

				game:GetService("Debris"):AddItem(damageIndicatorGui, 0.3)
			end
			currentHealth = humanoid.Health
		end)
	end)
end)

It’s a page where errors occur.

			damageIndicatorLabel:TweenSize(UDim2.new(1, 0, 1, 0),
				Enum.EasingDirection.In,
				Enum.EasingStyle.Sine,
				0.3,
				true
			)
1 Like

I’m not really that good with tweening, but the developer site tells you to use a LocalScript. Is this server-sided or local? If server-sided, then that might be the issue.

Could you tell me about this?

Hvataj
It tells you here to place a LocalScript, which is then later used to tween objects.

Regardless if it can work on server or not you should be handling Visual Tweens on the client as there is a multitude of reasons such as :

  • Tweens are smoother when handled by the client

  • Ping/Latency can affect the tweens performance when delivering the information to the client. If a client is laggy then the tween will also appear very choppy.

Use Tweenservice over “TweenSize/Position” as it has more functionality and allows for multiple goals to be set for properties.

TweenService = game:GetService("TweenService")
local myTween = {damageIndicatorLabe,TweenInfo.new(0.3,Enum.EasingStyle.Sine,Enum.EasingStyle.In,true),{Size = UDim2.new(1,0,1,0)}
myTween:Play()

The client can perform animations (tweens) at a refresh rate of 60hz, the server is limited to 30hz.

1 Like