TweenPosition script for GUI not working

I’m trying to make a textbutton that moves (only on the player’s screen) a couple seconds after the player joins the game. When I try this script, nothing happens. What am I doing wrong?

game.Players.PlayerAdded:Connect(function(player)
	print("Script works!")
	wait(2)
	script.Parent:TweenPosition(UDim2.new(.5, 0,0.3, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,.5,true)
end)

I’m new to scripting so I’m probably missing something simple.

the PlayerAdded thing fires whenever a player joins the game, not just the local player. Additionally, the script usually runs too late to detect when the local player joins.

Looking at your use case, you could probably just remove the PlayerAdded bit entirely, and just have the middle code.

1 Like

I recommend you use the tween service this way:


-- Services
local TweenService = game:GetService('TweenService') -- get the TweenService

-- The tweeninfo
local Info = TweenInfo.New(.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,true) -- Create the tweeninfo for the TweenService

-- Your goal table
local Goal = { -- Create a table for the  goal
    ['Position'] = UDim2.new(.5, 0, .3, 0)
}

game.Players.PlayerAdded:Connect(function(player)
	print("Script works!")
	wait(2)
	local MyTween = TweenService:Create(script.Parent,Info,Goal)
    MyTween:Play()
end)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.