Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Problem with GUI tweening and parameters. How can I fix it?

So, I have made a function that does GUI tweening, with 1 of the parameters representing the GUI that gets tweened. I tried putting the parameter in a variable.

Here is the script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("CannonGuiAppear")

remoteEvent.OnClientEvent:Connect(function() 
	local GUI = script.Parent.Parent.PlayerGui["Cannon-Popup"]
	local function GuiTween(gui,posX, poxY)
	
		gui:TweenPosition(
				UDim2.new(posX, 0, poxY, 0),
				"Out", -- Easing Direction
				"Sine", -- Easing Style
				1,
				true,
				game.Workspace.Cannon.Part.Controls.Disabled == false
			)
	end
	
	GuiTween(GUI.Frame1, 0.62, 0.898)
	GuiTween(GUI.Frame2, 0.261,0.929)
	GuiTween(GUI.Frame3,0.318,0.898)
	GuiTween(GUI.Frame4, 0.62,0.929)
	GuiTween(GUI.Frame5,0.357,0.859)
	GuiTween(GUI.TextLabel,0.357,0.88)
end)

And here is the error: 17:09:07.156 - Unable to cast value to function for the line that says; gui:TweenPosition(

Any idea how I can fix this? And yes, the remote event CAN run without issue of triggering it.

Note: This is a local script in StarterPlayerScripts (transferred to PlayerScripts in each player)

2 answers

✓ Accepted answer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("CannonGuiAppear")

local function GuiTween(gui,posX, poxY)
	gui:TweenPosition(
		UDim2.new(posX, 0, poxY, 0),
		"Out", -- Easing Direction
		"Sine", -- Easing Style
		1,
		true,
		function() -- Make this a function
			game.Workspace.Cannon.Part.Controls.Disabled = false
		end
	)
end


remoteEvent.OnClientEvent:Connect(function() 
    local GUI = script.Parent.Parent.PlayerGui["Cannon-Popup"]
    GuiTween(GUI.Frame1, 0.62, 0.898)
    GuiTween(GUI.Frame2, 0.261,0.929)
    GuiTween(GUI.Frame3,0.318,0.898)
    GuiTween(GUI.Frame4, 0.62,0.929)
    GuiTween(GUI.Frame5,0.357,0.859)
    GuiTween(GUI.TextLabel,0.357,0.88)
end)

You cannot tween the position of StarterGui's themselves. It only works on elements inside of a ScreenGui, such as a Frame or an ImageLabel.

5 comments

0

They are inside a ScreenGui. "Cannon-Popup" is a ScreenGui. When the function is ran, the first argument for the gui parameter is: GUI. (What ever I want to reference here.)

0

My bad, I didn't notice that

0

Here is the issue, and I am wondering if you know the solution. On line 08, when I try to reference the parameter, it won't let me. Any idea how to get around that? I tried using variables, nothing like that worked.

0

What I mean by "it won't let me", is it won't work. The error takes me to line 08, and I believe its cause I can't directly reference the parameter like that.

0

You're using a LocalScript, correct?

This discussion is preserved as it was. New answers, comments, and votes are closed.