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

Why is this incredibly simple tween script not working?

Asked by 5 years ago
Edited 5 years ago
gui = game:GetService("StarterGui")

script.Parent.MouseClick:Connect(function()
    gui.ScreenGui.Frame:TweenPosition(UDim2.new(0, 0, 0, 0),'In','Quad',1)
end)

This is a LocalScript, and I'm wondering what is wrong. Am I missing something?

0
try printing some important aspects of the frame and gui, for example : whether the frame is visible, if the gui is enabled, if the script isnt disabled, and the size and position of the screen gui. Also, MouseClick is an event for click detectors, so what is script.Parent? theking48989987 2147 — 5y
0
A click detector MustangHeart 67 — 5y
0
so maybe have a script that fires a remote event that tweens the gui on the client theking48989987 2147 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

What Vezious said is valid that you have to use player gui instead of starter gui but you also forget that the easing direction and the easing style are enum values, not strings. therefore, the correct local script code should be similar to:

local Player = game.Players.LocalPlayer
local Gui = Player.PlayerGui:FindFirstChild("ScreenGui")

script.Parent.MouseClick:Connect(function()
    Gui.Frame:TweenPosition(UDim2.new(0,0,0,0),Enum.EasingDirection.In,Enum.EasingStyle.Quad,1)
end)

also, as you have this in a mouse click,if you want to make it open and close, I also encourage the setting of the override variable to true as if a player clicks the button again before the tween finishes playing, it doesn't seem "glitchy"

local open = false
local Player = game.Players.LocalPlayer
local Gui = Player.PlayerGui:FindFirstChild("ScreenGui")

script.Parent.MouseClick:Connect(function()
    if not open then
        Gui.Frame:TweenPosition(UDim2.new(0,0,0,0),Enum.EasingDirection.In,Enum.EasingStyle.Quad,1,true)
        open = true
    else
        --tween to closed position
        open = false
    end
end)
0
The tweening styles can be written as a string... Lugical 425 — 5y
0
Really? The only time i saw the EasingStyle written as a string was in a function and the string was for Enum.EasingStyle[s] theking48989987 2147 — 5y
0
Still doesn't work. Idk why I'm having trouble, never had an issue before. MustangHeart 67 — 5y
0
Also there are no errors in the output, which is what I kind of hate. Doesn't tell you what's going on. :( MustangHeart 67 — 5y
View all comments (7 more)
0
Wait, I know the issue. It could be involving client server relations. Lugical 425 — 5y
0
Can’t type an answer now but simply learn about RemoteEvents and use them for this function Lugical 425 — 5y
0
i dont think REs are needed for tweening GUI elements in a local script theking48989987 2147 — 5y
0
Wait, nvm, but if it’s a local script, it should be in the GUI. If he wants a part to show up he has to refer like game.Workspace.blah Lugical 425 — 5y
0
yea, it does refer to the mouse click event, which is exclusive to click detectors theking48989987 2147 — 5y
0
I don't really know how to use RemoteEvents, so... MustangHeart 67 — 5y
0
It’s not RemoteEvents actually, but u have to relocate ur script to the GUI, and then change the reference to the detector Lugical 425 — 5y
Ad
Log in to vote
0
Answered by
Vezious 310 Moderation Voter
5 years ago

The problem is that you're Tweening the StarterGui one.

You need to get the player's clone of the GUI. It's found under Player.PlayerGui.

Therefore, your script should look like this:

local Player = game.Players.LocalPlayer
local Gui = Player.PlayerGui:FindFirstChild("ScreenGui")

script.Parent.MouseClick:Connect(function()
    Gui.Frame:TweenPosition(UDim2.new(0,0,0,0),"In","Quad",1)
end)
0
For whatever reason, it still doesn't work. Idk whats going on MustangHeart 67 — 5y
0
What's the error? Vezious 310 — 5y

Answer this question