GUI tweening problem

So, as you will see in the video and the script below, the Tween which I am scripting is not working, and I dont know the reason. Does it matter if it is in a User Input Service Statement? If yes, what should I do?

Here is the script:

local UIS = game:GetService("UserInputService")
local Objective = game.StarterGui.ObjectiveGui.Objective
local Objectives = game.StarterGui.ObjectiveGui.Objectives
local TweenService = game:GetService("TweenService")

UIS.InputBegan:Connect(function(inputObject, gameProcessedEvent)
	if (inputObject.KeyCode == Enum.KeyCode.Tab) then
 		Objective:TweenPosition(UDim2.new(0.95, 0, 0.025, 0),"Out", "Back",1)
	end
end)




:top: I was pressing the Tab button, but nothing happened.

1 Like

instead of referencing the Objective gui object from the StarterGui container, reference it from the PlayerGui container. The contents in the StarterGui replicate to the PlayerGui when the player first joins. Nothing changed in the StarterGui will replicate after that point. (after its contents have already replicated)

local player = game.Players.LocalPlayer
local ObjectiveGui = player.PlayerGui:WaitForChild("ObjectiveGui")
local Objective  = ObjectiveGui.Objective
local Objectives=  ObjectiveGui.Objectives
...
1 Like

You are missing parametres on you’re tween
Use
Objective:TweenPosition(UDim2.new(0.95, 0, 0.025, 0),“Out”, “Back”,1,false,nil)

Once a player joins a game, all Objects in game.StarterGui are cloned into the Player.PlayerGui folder. Hence, when you reference game.Startergui...., you’re referring to the original objects which weren’t cloned. Refer to these using a localscript in the game.StarterGui using script.Parent..... till you get you’re target ancestry or descendant object, in this case, a GuiObject.

Also, you’re only using the :TweenPosition function of GuiObjects, you’re not at all using TweenService here.
You have to create a Tween object with TweenService:Create(Instance, Info, PropertyTable) function then play it with TweenObject:Play() function.

Please refer to TweenService in the wiki for more info on this.

1 Like

This is not the problem, you can spit out the last two parameters.

The reply that @fredrick254 has given is the solution (I believe).
Also, I recommend you to use Enums next time. They are really really helpful.

Objective:TweenPosition(UDim2.new(0.95, 0, 0.025, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Back, 1)
1 Like

The StarterGUI is replicated in to the PlayerGui

Use these variables instead:

local Plr = game.Players.LocalPlayer;
local PlrUI = Plr:WaitForChild("PlayerGui");
local ObjectiveGui = PlrUI:WaitForChild("ObjectiveGui")
local Objective = ObjectiveGui:WaitForChild("Objective");
local Objectives = ObjectiveGui:WaitForChild("Objectives");
1 Like

Thanks to everyone who answered! :grin:
I haven’t chosen the solution, because I tried every one of them, and the all worked perfectly!
Thanks again,
Theyoloman1920

2 Likes