Gui Tween not working?

Hi so I’m trying to detect a winner for my game and just make a simple GUI tween upwards to everyone’s screen to display who won but for some reason, this doesn’t work at all?
There’s 0 errors so it’s making me even more confused.
Any help is appreciated!

--SERVERSCRIPT
local function winner(player)
    local playerName = player.Name
    local userId = player.UserId
    local thumType = Enum.ThumbnailType.AvatarThumbnail
    local thumSize = Enum.ThumbnailSize.Size420x420
    local image = game.Players:GetUserThumbnailAsync(userId, thumType, thumSize)
    winnerremoteEvent:FireClient(player, image)
end
--LOCAL SCRIPT
local TweenService = game:GetService("TweenService")

local player = game.Players.LocalPlayer
local winnerEvent = game.ReplicatedStorage.winner.winner

screenGui = player.PlayerGui:WaitForChild("Winner")
winnerGui = player.PlayerGui.Winner:WaitForChild("Frame")

local goal = UDim2.new(0.369,0,0.232,0)
local TIME = 2

local info = TweenInfo.new( --time, style,direction,repeatcount,reverse,delaytime
    TIME,    
    Enum.EasingStyle.Quart,
    Enum.EasingDirection.Out,
    0,
    false,
    5
)


winnerEvent.OnClientEvent:Connect(function(player, image)
    print("winner is ", player.Name)
    local displayGui = winnerGui:Clone()
    displayGui.PlayerImage.Image = image
    displayGui.PlayerName.Text = player.Name.." was the last one standing!"
    
    displayGui.Parent = screenGui.display
    displayGui.Visible = true
    
    newTween = TweenService:Create(displayGui, info, goal)
    
    newTween:Play()
    print("gui tween played")
end)

newTween.Completed:Connect(function(playbackState)
    
    if playbackState == Enum.PlaybackState.Completed then
        for _, v in pairs(screenGui.display:GetChildren()) do
            v:Destroy()
        end
    
    end
end)

You’re only firing it to the winner.
Are you trying to fire it to everyone?
If so, change this line

winnerremoteEvent:FireClient(player, image)
--to
winnerremoteEvent:FireAllClients(player, image)

Also, instead of cloning the GUI, why not just have it so you change one that’s always there already and just hide and unhide it when there is and isn’t a winner?

2 Likes

In addition to this, the function :TweenPosition, :TweenPositionAndSize and :TweenSize are functions of GuiObjects, and should be used in this case. If you would rather continue to use TweenService, the end goal of the tween must be in a dictionary, with a key-index pair of Property to Value. Here is an example below:

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out) -- Create TweenInfo

local Part = Instance.new("Part", workspace) -- Create a part in workspace and set properties
Part.Anchored = true
Part.Size = Vector3.new(5, 5, 5)
Part.Position = Vector3.new(0, 20, 0)

local NewTween = TS:Create(Part, TI, { -- Create new tween that changes position and size of part.
Position = Vector3.new(0, 40, 0),
Size = Vector3.new(10, 10, 10)
})

NewTween:Play() -- Play the tween

I hope this helps!

2 Likes

I updated my code and yes I didn’t clone the gui instead just change the visiblity property.

I put the goal into a dictionary it seems to work fine but the gui now doesn’t come back after a second round

It actually did show up on screen, am I forgetting to reset something perhaps?
UPDATED CODE:

local TweenService = game:GetService("TweenService")

local player = game.Players.LocalPlayer
local winnerEvent = game.ReplicatedStorage.winner.winner

screenGui = player.PlayerGui:WaitForChild("Winner")
winnerGui = player.PlayerGui.Winner:WaitForChild("Frame")

local goal = {Position = UDim2.new(0.369,0,0.232,0)}
local TIME = 2

local info = TweenInfo.new( --time, style,direction,repeatcount,reverse,delaytime
	TIME,	
	Enum.EasingStyle.Quart,
	Enum.EasingDirection.Out,
	0,
	false,
	5
)

winnerEvent.OnClientEvent:Connect(function(player, image)
	print("winner is ", player.Name)

	winnerGui.PlayerImage.Image = image
	winnerGui.PlayerName.Text = player.Name.." was the last one standing!"
	winnerGui.Visible = true
	
	newTween = TweenService:Create(winnerGui, info, goal)
	
	newTween:Play()
	print("gui tween played")
end)


newTween.Completed:Connect(function(playbackState)
	if playbackState == Enum.PlaybackState.Completed then
		winnerGui.Visible = false
	end
end)

If I could select two solutions, both of you guys helped me get this to work. Thank you so much!

1 Like