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

Why is this incredibly simple tween script not working?

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?

3 comments

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?

0

A click detector

0

so maybe have a script that fires a remote event that tweens the gui on the client

2 answers

✓ Accepted answer

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)

11 comments

0

The tweening styles can be written as a string...

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]

0

Still doesn't work. Idk why I'm having trouble, never had an issue before.

0

Also there are no errors in the output, which is what I kind of hate. Doesn't tell you what's going on. :(

0

Wait, I know the issue. It could be involving client server relations.

0

Can’t type an answer now but simply learn about RemoteEvents and use them for this function

0

i dont think REs are needed for tweening GUI elements in a local script

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

0

yea, it does refer to the mouse click event, which is exclusive to click detectors

0

I don't really know how to use RemoteEvents, so...

0

It’s not RemoteEvents actually, but u have to relocate ur script to the GUI, and then change the reference to the detector

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)

2 comments

0

For whatever reason, it still doesn't work. Idk whats going on

0

What's the error?

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