"Can only tween objects in workspace"

I have been working on a script that will move the text up for a few seconds, then move it back down. However, I got an error that says " Can only tween objects in the workspace " , even though I am using TweenPosition.

local textfunction = {}

local startergui = script.Parent
local text = script.Text.StatusText
local clone = text:Clone()
local value = script.Value.Value

function textfunction.movetext()
	clone.Text = value
	clone.TextTransparency = 0
	clone:TweenPosition(
		UDim2.new(0.25, 0,0.75, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		2,
		false
	)
	wait(1)
	clone:TweenPosition(
		UDim2.new(0.25, 0,1, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Quad,
		2,
		false
	)
	clone:Destroy()
end

return textfunction

When you’re testing / playing in your studio/game, StarterGui ‘becomes’ PlayerGui. Thus, don’t try to call StarterGui when testing/playing.

I assume this is a Module Script. Could you show us the script where you Play the Tweens?

1 Like

The script I play the tween so far are:

My door script (local script inside starter player script)

local tween = game:GetService("TweenService")

for _,door in pairs(game.Workspace:GetDescendants()) do
	if door:IsA'Model' then
		if door.Name == "Door" then
			local prompt = door.Base.ProximityPrompt
			local locked = door.Locked
			local hinge = prompt.Parent.Parent.Doorframe.Hinge
			local openandclose = script["Open/Close"]
			local locksound = script.Locked
			local player = game.Players.LocalPlayer
			local textscript = player.PlayerGui:WaitForChild("Text Script")
			local value = textscript.Value.Value
			
			local goalOpen = {}
			goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(45), 0)

			local goalClose = {}
			goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
			
			local Info = TweenInfo.new(1)
			local Open = tween:Create(hinge, Info, goalOpen)
			local Close = tween:Create(hinge, Info, goalClose)
			
			if locked.Value == true then
				prompt.HoldDuration = 0
			end
			
			prompt.Triggered:Connect(function()
				if locked.Value == true then
					if prompt.ActionText ~= "Unlock" then
						locksound:Play()
						value = "The door is locked!"
						local textfunction = require(textscript)
						textfunction.movetext()
					elseif prompt.ActionText == "Unlock" then
						locked.Value = false
						Open:Play()
						openandclose:Play()
						prompt.ActionText = "Close"
						prompt.HoldDuration = 1
						prompt.Enabled = false
						wait(1)
						prompt.Enabled = true
					end
				else
					if prompt.ActionText == "Close" then
						Close:Play()
						openandclose:Play()
						prompt.ActionText = "Open"
						prompt.Enabled = false
						wait(1)
						prompt.Enabled = true
					else
						Open:Play()
						openandclose:Play()
						prompt.ActionText = "Close"
						prompt.Enabled = false
						wait(1)
						prompt.Enabled = true
					end
				end
			end)
		end
	end
end

And my tool script (A normal script in workspace)

for _,item in pairs(script.Parent:GetDescendants()) do
	if item:IsA'Model' then
		local ToolName = item.Name
		local Storage = game.ServerStorage 
		
		local Part = item.Handle
		local prompt = item.invis.ProximityPrompt

		
		prompt.Triggered:connect(function(player)
			print("Tool prompt is being activated")
			prompt.Enabled = false
			if player and player.Character then
				local Backpack = player:WaitForChild("Backpack")
				local textscript = player.PlayerGui:WaitForChild("Text Script")
				local value = textscript.Value.Value
				for i = 1, #ToolName do
					local Tool = Storage:FindFirstChild(ToolName)
					if Tool then
						if not Backpack:FindFirstChild(ToolName) and not player.Character:FindFirstChild(ToolName) then
							Tool:clone().Parent = Backpack
							print("Tool is cloned!")
						else
							print("Tool did not clone")
							value = "You already have this item!"
							local textfunction = require(textscript)
							textfunction.movetext()
						end
					end
				end
			end
			wait(1)
			prompt.Enabled = true
		end)
	end
end

also I don’t even know why I set a variable for startergui since I never use it, and it’s useless.

1 Like

I don’t understand why it gives me an error, tween position are literally for gui.

Still can’t figure out what’s wrong with it.

The error is rather deceiving; it would appear as if your “StatusText” TextLabel isn’t located inside of a ScreenGui, thus signaling the warning.

But… my textlabel is located inside a screengui, is there a way to fix it?

2022-04-11

Before doing tweens, parent the clone to the correct area so clone.Parent=TextGuiObject

Am I correct that clone is a ui element?

Ok, but it still gives me the same error.

local textfunction = {}

local text = script.Text.StatusText
local clone = text:Clone()
local value = script.Value.Value

clone.Parent = text.Parent

function textfunction.movetext()
	clone.Text = value
	clone.TextTransparency = 0
	clone:TweenPosition(
		UDim2.new(0.25, 0,0.75, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		2,
		false
	)
	wait(1)
	clone:TweenPosition(
		UDim2.new(0.25, 0,1, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Quad,
		2,
		false
	)
	clone:Destroy()
end

return textfunction

You’re destroying the Clone the moment you call TweenPosition, which is not a yielding function. You need to wait(2) for the tween to finish. TweenPosition() does not yield code, you must yield the code yourself.

nvm Im confused now…

Its inside gui…

It still gives me the same error even though I wait an extra second after the tween is finished.

local textfunction = {}

local text = script.Text.StatusText
local clone = text:Clone()
local value = script.Value.Value

clone.Parent = text.Parent

function textfunction.movetext()
	clone.Text = value
	clone.TextTransparency = 0
	clone:TweenPosition(
		UDim2.new(0.25, 0,0.75, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Quad,
		2,
		false
	)
	wait(3)
	clone:TweenPosition(
		UDim2.new(0.25, 0,1, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Quad,
		2,
		false
	)
	wait(3)
	clone:Destroy()
end

return textfunction

what line does the error lead to?

It leads to line 12, which is

clone:TweenPosition(

Sorry for the late reply but it’s because you’re parenting it to a gui that’s under a script (not under a PlayerGui component, therefore not in a GUI’s “workspace”)
Parent the Clone to a GUI that’s actually under a PlayerGui, it’ll fix your issue.

I just made the script a child to the GUI, but it still gives me the same error.

It doesn’t matter what I did, it just keeps giving me the exact same error.

Maybe try using TweenService on a GUI. It acts similarly to TweenPosition, but it has more feature. Such as ‘Completed’ event, which you can wait for the tween to finish tweening, and delete the clone.

I used TweenService for my XP manager gui, and it worked pretty well.

I hope this helps with your situation. If something is not working, let me know!

It still didn’t work, but at least it gives me a new error.

The error leads to this line from the local script that requires it:

local textfunction = require(textscript)
local player = game.Players.LocalPlayer
local textscript = player.PlayerGui:WaitForChild("Text"):WaitForChild("Text Script")