Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago
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)
Ad
Log in to vote
0
Answered by
zane21225 243 Moderation Voter
3 years ago

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.

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.) cookie_more 30 — 3y
0
My bad, I didn't notice that zane21225 243 — 3y
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. cookie_more 30 — 3y
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. cookie_more 30 — 3y
0
You're using a LocalScript, correct? zane21225 243 — 3y

Answer this question