Tween not playing when player joins

I’m trying to play tweens to show my UI when the player joins and respawns. This is my script, but for some reason it doesn’t work. There is nothing in output

local tweenService = game:GetService("TweenService")

local player = game.Players.LocalPlayer
local orderText = player.PlayerGui:WaitForChild("Starter").Background.Main.Order
local playBttn = player.PlayerGui:WaitForChild("Starter").Background.Main.Play
local shopBttn = player.PlayerGui:WaitForChild("Starter").Background.Main.Shop
local rose = player.PlayerGui:WaitForChild("Starter").Background.Main.Order.rose

local orderInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
local playInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
local shopInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
local roseInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.In)

local playGoal1 = {Position = UDim2.new({0.352, 0},{0.401, 0})}
local shopGoal1 = {Position = UDim2.new({0.352, 0},{0.625, 0})}
local orderGoal1 = {TextTransparency = 0}
local roseGoal1 = {ImageTransparency = 0}

local playGoal2 = {TextTransparency = 1}
local shopGoal2 = {TextTransparency = 1}
local orderGoal2 = {TextTransparency = 1}
local roseGoal2 = {ImageTransparency = 1}

local orderTween1 = tweenService:Create(orderText, orderInfo, orderGoal1)
local orderTween2 = tweenService:Create(orderText, orderInfo, orderGoal2)
local roseTween1 = tweenService:Create(rose, roseInfo, roseGoal1)
local roseTween2 = tweenService:Create(rose, roseInfo, roseGoal2)
local playTween1 = tweenService:Create(playBttn, playInfo, playGoal1)
local playTween2 = tweenService:Create(playBttn, playInfo, playGoal2)
local shopTween1 = tweenService:Create(shopBttn, shopInfo, shopGoal1)
local shopTween2 = tweenService:Create(shopBttn, shopInfo, shopGoal2)

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		orderTween1:Play()
		roseTween1:Play()
		task.wait(2.5)
		playTween1:Play()
		task.wait(1.5)
		shopTween1:Play()	
		
	end)
end)

it’s a localscript inside StarterPlayerScripts

Can’t you just do this? No Player Added Event

player.CharacterAdded:Connect(function()
		orderTween1:Play()
		roseTween1:Play()
		task.wait(2.5)
		playTween1:Play()
		task.wait(1.5)
		shopTween1:Play()	
end)

(At the end of your script)

yes i could but that doesn’t fix my issue

Can you do:

repeat task.wait() until player.Character:FindFirstChild("Humanoid") ~= nil
		orderTween1:Play()
		roseTween1:Play()
		task.wait(2.5)
		playTween1:Play()
		task.wait(1.5)
		shopTween1:Play()	

1 Like

As a heads up too, that’s a ton of variables for something that I feel shouldn’t need that many at all. Just as a warning because Writing these takes time, and can get complex if you wanted to do more with that script.

not sure how i would write it with less variables

give me like 10 minutes to write you a better script, with a lot less. One second

1 Like

Here is my new script

local tweenService = game:GetService("TweenService")

local player = game.Players.LocalPlayer
local orderText = player.PlayerGui:WaitForChild("Starter").Background.Main.Order
local playBttn = player.PlayerGui:WaitForChild("Starter").Background.Main.Play
local shopBttn = player.PlayerGui:WaitForChild("Starter").Background.Main.Shop
local rose = player.PlayerGui:WaitForChild("Starter").Background.Main.Order.rose



local playGoal1 = {Position = UDim2.new({0.352, 0},{0.401, 0})}
local shopGoal1 = {Position = UDim2.new({0.352, 0},{0.625, 0})}
local TextTransparencyVisible = {TextTransparency = 0}
local ImageTransparencyVisible = {ImageTransparency = 0}

local TextTransparencyInvisble = {TextTransparency = 1}
local ImageTransparencyInvisble = {ImageTransparency = 1}



local function PlayATween(Part, Goal, NumberOfSeconds)
	--NumberOfSeconds is how long the Tween will play for!
	local infoForTweens = TweenInfo.new(NumberOfSeconds, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
	local Tween = tweenService:Create(Part, infoForTweens, Goal):Play()
end



repeat task.wait() until player.Character:FindFirstChild("Humanoid") ~= nil
coroutine.wrap(PlayATween)(orderText, TextTransparencyVisible, 2)
coroutine.wrap(PlayATween)(rose, ImageTransparencyVisible, 2)
task.wait(2.5)
coroutine.wrap(PlayATween)(playBttn, playGoal1, 1)
task.wait(1.5)
coroutine.wrap(PlayATween)(shopBttn, shopGoal1, 1)	

I am sure I could even get this down Even more. But yea. If there is errors let me know, or if you have questions!

1 Like

Please consider organizing your code more thoroughly if you can, using something like tables can help make your code easier to look at

One reason why it may not work, is because you’re attempting to call the PlayerGui early on when you should be yielding for it instead, even though you have the right idea of using WaitForChild() the Player may not be able to detect it quick enough the moment they first join the game when indexing, and returns back with an error

Another thing is that the PlayerAdded Event specifically on the client will only work for those other players that join the game, and not your own as I stated earlier with the PlayerAdded Event not firing fast enough to detect your own player, but others

You would have to create a local function for when both you, as the individual Player & other players join the game so we’d need to set up something like this in order to properly make it work:

local tweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local PlrGui = player:WaitForChild("PlayerGui")

local Starter = PlrGui:WaitForChild("Starter")
local Background = Starter:WaitForChild("Background")
local Main = Background:WaitForChild("Main")

local TweenInfos = {
	LongTween = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.In),
	ShortTween = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In),
}

local TweenProperties = {
    PlayGoal = {Position = UDim2.new(0.352, 0, 0.401, 0)},
	ShopGoal = {Position = UDim2.new(0.352, 0, 0.625, 0)},
	
	TextFade = {TextTransparency = 1},
	TextAppear = {TextTransparency = 0},
	
	ImageFade = {ImageTransparency = 1},
	ImageAppear = {ImageTransparency = 0}
}

local function CallTweens()
	local Tween = TweenService:Create(Main:WaitForChild("Order"), TweenInfos.LongTween, TweenProperties.TextAppear)
	Tween:Play()
	
	local RoseTween = TweenService:Create(Main:WaitForChild("Order"):WaitForChild("Rose"), TweenInfos.LongTween, TweenProperties.ImageAppear)
	RoseTween:Play()
	
	task.wait(2.5)
	
	local PlayTween = TweenService:Create(Main:WaitForChild("Play"), TweenInfos.ShortTween, TweenProperties.PlayGoal)
	PlayTween:Play()
	
	task.wait(1.5)
	
	local ShopTween = TweenService:Create(Main:WaitForChild("Shop"), TweenInfo.ShortTween, TweenProperties.ShopGoal)
	ShopTween:Play()
end

CallTweens()

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(CallTweens)
end)

Thank you so much! this seems a lot more efficient than my original script

It is. What the function does is it takes what you want, and because there was a lot of pattern in your tweens, It’s easy to just add them as a variable in the function and call that tween.

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