Very simple tweening script doesn't work?

I’m new to scripting, so apologies if this post is structured poorly as it is my first ever.

Basically, I’m trying to have it so when a player joins the game, they see an intro gui that slides out of the way after a little bit.

Problem is though, it just doesn’t move. I’ve watched dozens of tutorials, gone over several similar questions, and changed the code a bunch. I’ve made sure that the coordinates are right, as well. It’s probably some little thing that I didn’t notice, so please help.

game.Players.PlayerAdded:Connect(function(player)
	wait(1)
	game.Players.LocalPlayer.PlayerGui.Intro.Frame:TweenPosition(UDim2.new(-2,0,0,0),"Out","Elastic",2,false)
end)

This script, and the screengui, are located in StarterGui

Is this a server script or a local script?

1 Like

It’s a local script, which I think is the right one to use

I think you can do it like this instead

Put a localscript inside of the Intro ScreenGui with this code

wait(1)

script.Parent.Frame:TweenPosition(UDim2.new(-2,0,0,0),"Out","Quad",2,false)

Also, LocalScripts cannot use PlayerAdded, that’s why your code didn’t work

PlayedAdded can be trigged in a local script, but it won’t work if your trying to detect the LocalPlayer that joined.

2 Likes

I see, I thought it didn’t work in general. Sorry for the misinformation

What would be the correct way of doing this then?

Use the script that @EmbatTheHybrid provided.

1 Like
repeat wait(0.5) until player:FindFirstChild("PlayerGui") 
--your code

Instead of PlayerAdded Function

1 Like

As @IEnforce_Lawz mentioned, my script should work fine for your needs, I don’t believe it requires any changes. If you want it to work after the player’s character has been added, I could you can use this instead

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

wait(1)

script.Parent.Frame:TweenPosition(UDim2.new(-2,0,0,0),"Out","Quad",2,false)

Both will work regardless

1 Like
repeat wait(0.5) until player:FindFirstChild("PlayerGui")

Why not just

player:WaitForChild("PlayerGui")

?

2 Likes

Oh yea make sense. But it can sometimes infinite yield.

if player:WaitForChild("PlayerGui") then
--your code
1 Like
local player = game.Players.LocalPlayer

repeat wait(0.5) until player:FindFirstChild("PlayerGui") 

wait(1)

script.Parent.Frame:TweenPosition(UDim2.new(-2,0,0,0),"Out","Quad",2,false)

This works, thanks everybody!

2 Likes

You dont need to add wait(1) if its not needed.

1 Like

I don’t want it to happen right away, I’ll be editing the wait to make it perfect later

The

repeat wait(0.5) until player:FindFirstChild("PlayerGui") 

Is not needed, if the script is running, then PlayerGui already exists

Mark your post as the solution to help people who view this topic in the future.

Its his script, let him do what he desires.

If it infinitely yields, it will infinitely yield, not return nil. It doesn’t keep running the script until the PlayerGui exists.

3 Likes