"Can only tween objects in the workspace" error when trying to tween Frame in ScreenGui

Hello,

I’m currently trying to create a tween created via a ModuleScript, however I’m getting the error “Can only tween objects in the workspace”. Here’s my code:

local function pushMenu(nextMenu, prevMenu)
	if prevMenu then
		prevMenu:TweenPosition(UDim2.new(-1, 0, 0, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 1, true)
	end

	-- more code here, not related to the error
end

-- For example, trying to run:
local mainFrameShield = Instance.new('Frame')
mainFrameShield.Name = "mainFrameShield"
mainFrameShield.Size = UDim2.new(1, 0, 1, 36)
mainFrameShield.Position = UDim2.new(0, 0, 0, -36)
mainFrameShield.BackgroundTransparency = 1
mainFrameShield.BackgroundColor3 = Color3.new(31/255, 31/255, 31/255)
mainFrameShield.BorderColor3 = Color3.new(27/255, 42/255, 53/255)
mainFrameShield.BorderSizePixel = 0
mainFrameShield.Visible = false
mainFrameShield.ZIndex = 3
mainFrameShield.Parent = mainSGUI

mainFrame = Instance.new('Frame')
mainFrame.Name = "mainFrame"
mainFrame.Size = UDim2.new(1, 0, 1, 0)
mainFrame.Position = closed_Position
mainFrame.Active = true
mainFrame.BackgroundTransparency = 0.65
mainFrame.BackgroundColor3 = Color3.new(31/255, 31/255, 31/255)
mainFrame.BorderSizePixel = 0
mainFrame.ZIndex = 4
mainFrame.ClipsDescendants = true
mainFrame.Parent = mainFrameShield

local function createMenuFrame(name, position)
	local frame = Instance.new('Frame')
	frame.Name = name
	frame.Size = UDim2.new(1, 0, 1, 0)
	frame.Position = position
	frame.BackgroundTransparency = 1
	frame.ZIndex = 5

	return frame
end

local rootMenuFrame = createMenuFrame("rootMenuFrame", UDim2.new(0, 0, 0, 0))
rootMenuFrame.Parent = mainFrame

pushMenu(rootMenuFrame, rootMenuFrame)

will return error “Can only tween objects in the workspace”.

Been stuck on this for about an hour and have no clue what’s going on. Anyone able to help out, please? Has to be created using a Script.

Thanks,
p0s_0

1 Like

Pretty sure this only happens when things are parented to nil. From what I can see, everything should be a descendant of mainSGUI, correct? Are you ever declaring mainSGUI? That’s really the only thing that I could see that would be wrong.

You also said that this is being called from a modulescript, what is being called from the module and what is inside of the module?

mainSGUI is defined as script.Parent. On require(), it runs all of the code in the ModuleScript.

1 Like

Thanks for that.

When you say it’s defined as script.Parent, are you declaring it inside or outside of the module? If the localscript and modulescript are the children of the same parent, that shouldn’t matter but assuming they aren’t it does depend on what is declaring the variable.

I’m declaring it at the top, inside of the module.

local mainSGUI = script.Parent -- for example
1 Like

Thanks for that.

Just to be clear, you want it to be the parent of the ModuleScript? If so, are you sure it is a descendant of a ScreenGui or of workspace? If it’s of ReplicatedStorage, it gives me that same error as well as the unable to load module error.

(Sorry for long wait, had to make sure that was the case)

The mainSGUI is the parent of PlayerGui, and I want all frames inside of that. The ModuleScript is hosted in PlayerGui aswell.

1 Like

Whats the code there. TweenPosition doesn’t yield the script

1 Like

It goes to the corresponding next page that I left out, as I determined it wasn’t the cause of the error.

1 Like

are you sure it doesnt Destroy the prevMenu

1 Like

Yeah, I’m sure. I checked, afaik.

Anyways, I’m tired and I’m going to go to bed. If you find something that works, post it here.

1 Like

Could you provide a screenshot of the hierarchy? I tried your script and it didn’t seem to error.

It’s like this, correct?
Capture d’écran, le 2021-01-14 à 23.13.36

Yeah, the hierarchy looks like this.

1 Like

Fixed by myself, used TweenService instead. Thanks!

1 Like