Need Help with TweenService

Hello Devs,

Whenever a player moves or jumps how would i make a textlabel that displays that the “Players Name” and fades after 5 seconds but if another player has moved within the 5 seconds fade time a replica of the textlabel with the player who moved this time is displayed underneath the original one then after 5 seconds it fades, kinda like a list system. Its quite to hard to explain but when the old one has faded the new one then moves up.

Ive tried this script it dosent work well at all:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TimerEvent = ReplicatedStorage:WaitForChild("TimerEvent")


local function moveTextLabelToPosition(textLabel)
	local tweenService = game:GetService("TweenService")
	local tweenInfo = TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

	local endPosition = UDim2.new(0.497, 0,0.029, 0)

	local tweenProperties = {
		Position = endPosition,
	}

	local tween = tweenService:Create(textLabel, tweenInfo, tweenProperties)
	tween:Play()
	tween.Completed:Connect(function()
		textLabel.Position = UDim2.new(0.497, 0,0.029, 0)
		textLabel.TextTransparency = 0
	end)
end
local moveDirectionFlags = {}

local function fadeOutTextLabel(textLabel)
	local tweenService = game:GetService("TweenService")
	local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

	local endTransparency = 1

	local tweenProperties = {
		TextTransparency = endTransparency
	}

	local tween = tweenService:Create(textLabel, tweenInfo, tweenProperties)
	tween:Play()
	tween.Completed:Connect(function()
		textLabel.TextTransparency = 0
		textLabel.Text = ""
	end)
end

local function onMove(player)
	if not moveDirectionFlags[player] then
		moveDirectionFlags[player] = true
		local message = player.Name .. " has moved :("
		TimerEvent:FireAllClients(player)

		local moveNameGui = player.PlayerGui:FindFirstChild("PlayerMovedGui")
		if moveNameGui then
			local textLabel = moveNameGui.PlayerMove.PlayerMoved
			if textLabel then
				textLabel.Text = message
				moveTextLabelToPosition(textLabel)
				wait(2)
				fadeOutTextLabel(textLabel)
				moveDirectionFlags[player] = false
			end
		end
	end
end

for _, player in ipairs(game.Players:GetPlayers()) do
	player.CharacterAdded:Connect(function(character)
		local hum = character:WaitForChild("Humanoid")
		hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
			onMove(player)
		end)
	end)
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local hum = character:WaitForChild("Humanoid")
		hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
			onMove(player)
		end)
	end)
end)


game.Players.PlayerRemoving:Connect(function(player)
	moveDirectionFlags[player] = nil
end)

Please help ive been trying this for hours, Thanks!

The behavior of moving GUI elements up/down or out of the way sounds like the functionality a UIListLayout provides if that’s what you’re talking about.

1 Like

How do i tween a textlabel into the frame with a ui label do you think?

Are you trying to just make it fade out or are you trying to like smoothly move it out of the way when a new TextLabel shows up?

if there are no textlabels inside the frame im trying to make it just smoothly fade in from the top of the screen but if there is already a textlabel im trying to make it to just appear under the textlabel

The UIListLayout will handle the placements for you if you set it up like this:
image
You might have to modify some of its properties but by default it will sort from top to bottom placing new elements below older elements.
It looks like you already have some code for fading out the TextLabels and you should be able to just use that code again but in reverse for fading in.

thanks ive tried this and it works but do you think its possible to tween in the textlabel smoothly into the frame

You could try having a list of invisible TextLabels then Tweening separate TextLabels to their position so while the list of invisible TextLabels will shift instantly, the visible ones will smoothly move to that position.

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