Tween Gui Script Not Detecting Object under Parent of Parent

  1. What do you want to achieve? Keep it simple and clear!

I am attempting to edit my Gui script so that when my Stats Gui tweens on screen the Scouter Gui tweens off screen if it is currently on screen. I’ve already done this with my Scouter Gui so that when it tweens on screen the Stats Gui tweens off screen if it is currently on screen.

  1. What is the issue? Include screenshots / videos if possible!

The ScouterGui is not being recognized as a valid member of PlayerGui despite the same thing being done in a script for the ScouterGui.

StarterGui


FrameMovementScouter
FrameMovementStats

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Analyzing the output.

Stats Gui Movement Script:

--
local StatsButton = script.Parent.TextButton
local StatsFrame = script.Parent.StatFrame
local OrangeFrame = script.Parent.Orange
local LightOrangeFrame = script.Parent.LightOrange
local StatLabel = script.Parent.StatLabel
local ScouterFrame = script.Parent.Parent.ScouterGui.ScouterFrame

StatsButton.MouseButton1Up:Connect(function()
	
	 if StatsFrame.Position == UDim2.new(0.746,0,0.519,0)
	then 
		StatsFrame:TweenPosition(UDim2.new(1,0,0.519,0),"InOut","Quint",1,false)
	elseif StatsFrame.Position == UDim2.new(1,0,0.519,0)	
	then
		StatsFrame:TweenPosition(UDim2.new(0.746,0,0.519,0),"InOut","Quint",1,true)	
	end
	
	if OrangeFrame.Position == UDim2.new(0.746,0,0.489,0)
	then 
		OrangeFrame:TweenPosition(UDim2.new(1,0,0.489,0),"InOut","Quint",1,false)
	elseif OrangeFrame.Position == UDim2.new(1,0,0.489,0)	
	then
		OrangeFrame:TweenPosition(UDim2.new(0.746,0,0.489,0),"InOut","Quint",1,true)	
	end
	
	if LightOrangeFrame.Position == UDim2.new(0.746,0,0.489,0)
	then 
		LightOrangeFrame:TweenPosition(UDim2.new(1,0,0.489,0),"InOut","Quint",1,false)
	elseif LightOrangeFrame.Position == UDim2.new(1,0,0.489,0)	
	then
		LightOrangeFrame:TweenPosition(UDim2.new(0.746,0,0.489,0),"InOut","Quint",1,true)	
	end
	
	if StatLabel.Position == UDim2.new(0.79,0,0.501,0)
	then 
		StatLabel:TweenPosition(UDim2.new(1,0,0.501,0),"InOut","Quint",1,false)
	elseif StatLabel.Position == UDim2.new(1,0,0.501,0)	
	then
		StatLabel:TweenPosition(UDim2.new(0.79,0,0.501,0),"InOut","Quint",1,true)	
	end
	
	if ScouterFrame.Position == UDim2.new(0.717,0,0.515,0)
	then 
		ScouterFrame:TweenPosition(UDim2.new(1,0,0.515,0),"InOut","Quint",1,false)
	end
	
end)

Scouter Gui movement script (Working):

--
local ScouterButton = script.Parent.TextButton
local ScouterFrame = script.Parent.ScouterFrame
local LightOrange = script.Parent.Parent.StatsGui.LightOrange
local Orange = script.Parent.Parent.StatsGui.Orange
local StatFrame = script.Parent.Parent.StatsGui.StatFrame
local StatLabel = script.Parent.Parent.StatsGui.StatLabel




ScouterButton.MouseButton1Up:Connect(function()
	
	 if ScouterFrame.Position == UDim2.new(0.717,0,0.515,0)
	then 
		ScouterFrame:TweenPosition(UDim2.new(1,0,0.515,0),"InOut","Quint",1,false)
	elseif ScouterFrame.Position == UDim2.new(1,0,0.515,0)	
	then
		ScouterFrame:TweenPosition(UDim2.new(0.717,0,0.515,0),"InOut","Quint",1,true)	
	end
	
	if LightOrange.Position == UDim2.new(0.746,0,0.489,0)
	then 
		LightOrange:TweenPosition(UDim2.new(1,0,0.489,0),"InOut","Quint",1,false)
	end
	
	if Orange.Position == UDim2.new(0.746,0,0.489,0)
	then 
		Orange:TweenPosition(UDim2.new(1,0,0.489,0),"InOut","Quint",1,false)
	end
	
	if StatFrame.Position == UDim2.new(0.746,0,0.519,0)
	then 
		StatFrame:TweenPosition(UDim2.new(1,0,0.519,0),"InOut","Quint",1,false)
	end
	
	if StatLabel.Position == UDim2.new(0.79,0,0.501,0)
	then 
		StatLabel:TweenPosition(UDim2.new(1,0,0.501,0),"InOut","Quint",1,false)
	end
	
end)

Many thanks,
Sephorothy

Try using :WaitForChild(“ScouterGui”)

Make sure your UI elements are parented correctly and that you’re correctly defining parent/child elements.

Edit
I tried this and got the same error, please correct me if I am using it incorrectly.

You put :WaitForChild("ScouterGui") in place of .ScouterGui.

EDIT: Documentation for it here if you need.

Ah I see, my bad.

Edit2

This fixed the issue of the entire script not working however I cannot specify the ScouterFrame to tween as seen below.

ScouterFrameMovement

I believe this is because I have an object inside of my ScouterGui setup which is the frame I’m targeting rather than the entire GUI. This object I’m attempting to tween is ScouterFrame.
ScouterGuiFull

Edit3

I fixed the issue by adding .ScouterFrame after :WaitForChild(“ScouterGui”) which I did not initially think to do as I did not think it was possible.

Regardless the resulting script only pushes the ScouterFrame Gui back outside of the screen about 50% of the time, is it possible to increase the success rate of the script?

Here is the entire script:

local StatsButton = script.Parent.TextButton
local StatsFrame = script.Parent.StatFrame
local OrangeFrame = script.Parent.Orange
local LightOrangeFrame = script.Parent.LightOrange
local StatLabel = script.Parent.StatLabel

local ScouterFrame = script.Parent.Parent:WaitForChild("ScouterGui").ScouterFrame

StatsButton.MouseButton1Up:Connect(function()
	
	 if StatsFrame.Position == UDim2.new(0.746,0,0.519,0)
	then 
		StatsFrame:TweenPosition(UDim2.new(1,0,0.519,0),"InOut","Quint",1,false)
	elseif StatsFrame.Position == UDim2.new(1,0,0.519,0)	
	then
		StatsFrame:TweenPosition(UDim2.new(0.746,0,0.519,0),"InOut","Quint",1,true)	
	end
	
	if OrangeFrame.Position == UDim2.new(0.746,0,0.489,0)
	then 
		OrangeFrame:TweenPosition(UDim2.new(1,0,0.489,0),"InOut","Quint",1,false)
	elseif OrangeFrame.Position == UDim2.new(1,0,0.489,0)	
	then
		OrangeFrame:TweenPosition(UDim2.new(0.746,0,0.489,0),"InOut","Quint",1,true)	
	end
	
	if LightOrangeFrame.Position == UDim2.new(0.746,0,0.489,0)
	then 
		LightOrangeFrame:TweenPosition(UDim2.new(1,0,0.489,0),"InOut","Quint",1,false)
	elseif LightOrangeFrame.Position == UDim2.new(1,0,0.489,0)	
	then
		LightOrangeFrame:TweenPosition(UDim2.new(0.746,0,0.489,0),"InOut","Quint",1,true)	
	end
	
	if StatLabel.Position == UDim2.new(0.79,0,0.501,0)
	then 
		StatLabel:TweenPosition(UDim2.new(1,0,0.501,0),"InOut","Quint",1,false)
	elseif StatLabel.Position == UDim2.new(1,0,0.501,0)	
	then
		StatLabel:TweenPosition(UDim2.new(0.79,0,0.501,0),"InOut","Quint",1,true)	
	end
	
	if ScouterFrame.Position == UDim2.new(0.717,0,0.515,0)
	then 
		ScouterFrame:TweenPosition(UDim2.new(1,0,0.515,0),"InOut","Quint",1,false)
	end
	
end)

Mark whichever reply as the Solution so people know for people who stumble upon this problem also.

1 Like

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