"Can only tween objects in workspace"

I am making a touch-shop gui and it works fine. However, for some reason, after dying, when I try to access the shop it gives me this error:

“Can only tween objects in workspace”

Here is the script:

local players = game:GetService("Players")
local playerGUI = players.LocalPlayer:WaitForChild('PlayerGui')
local trailGui = playerGUI:WaitForChild("EquipTrails")
local ui1 = trailGui:WaitForChild("ScrollingFrame")
local ui2 = trailGui:WaitForChild("Background")
local replicatedStorage = game:GetService("ReplicatedStorage")
local remote = replicatedStorage:WaitForChild("TweenTrailsUI")

remote.OnClientEvent:Connect(function(direction)
	if direction == "Up" then
			print(ui1.Parent)
		ui1:TweenPosition(UDim2.new(0.272, 0,0.27, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.25, false)
		print(ui2.Parent)
		ui2:TweenPosition(UDim2.new(0.5, 0,0.6, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.25, false)
	else
		print(ui1.Parent)
		ui1:TweenPosition(UDim2.new(0.272, 0,1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.25, false)
		print(ui2.Parent)
		ui2:TweenPosition(UDim2.new(0.5, 0,1.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.25, false)
	end
end)

How can I fix this? I know that this error is called when the parent of the gui = nil but when I activate the shop my character and player are fully loaded. The error comes when I try to tween the position of the UI.

1 Like

Nevermind, I was able to fix the error by moving most of the variables inside of the function.

I understand that this is technically solved, but is this a GUI that everyone sees or is it only the local player who sees it?

Local player

eeeeeeeeeeeeeeeeeeeeeeeeee

So what’s the point of overcomplicating the script?

If you don’t need to use the server, I wouldn’t involve it since it’s more places for the code to go wrong.

Note: I am an idiot and misread your event that was being fired to the client, my bad.

I thought about this, but its like a dumb simulator cash grab so I dont care lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.