New GUI element not showing up?

I’m trying to make a localscript which shows the player how much money they have just picked up from a coin collect, though I believe my tween is not working correctly.

The tween is supposed to make the popup slide up from behind another GUI object and slide back down behind it before being deleted again.

Here is the local script (showing only the info related to the tween):

        -- Tween

	local Pos1 = UDim2.new(0.075, 0, 0.489, 0) -- Where the tween starts and returns to
	local Pos2 = UDim2.new(0.306, 0, -1, 0) -- Where the tween ends

	local TweenInfo = TweenInfo.new(2)

	local Tween1 = TweenService:Create(TextLabel, TweenInfo, {Position = Pos2})
	
	Tween1:Play()
end)

What can I do to make this tween function correctly?

Here is the full localscript for more context
local RS = game:GetService("ReplicatedStorage"):WaitForChild("CoinCollect"):WaitForChild("CollectCoin")

local TweenService = game:GetService("TweenService")

-- DoorPart

RS.OnClientEvent:Connect(function(reward)
	
	script.Win:Play()
	
	local TextLabel = Instance.new("TextLabel")

	--Properties:

	TextLabel.Parent = game.StarterGui.Main
	TextLabel.Name = "CoinReward"
	TextLabel.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
	TextLabel.BackgroundTransparency = 1.000
	TextLabel.BorderColor3 = Color3.fromRGB(0, 0, 0)
	TextLabel.BorderSizePixel = 0
	TextLabel.Position = UDim2.new(0.075, 0, 0.489, 0)
	TextLabel.Size = UDim2.new(0.113149211, 0, 0.0604938269, 0)
	TextLabel.ZIndex = -5
	TextLabel.Font = Enum.Font.SourceSansBold
	TextLabel.Text = reward
	TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
	TextLabel.TextScaled = true
	TextLabel.TextSize = 14.000
	TextLabel.TextWrapped = true
	
	local Pos1 = UDim2.new(0.075, 0, 0.489, 0) -- Where the tween starts and returns to
	local Pos2 = UDim2.new(0.306, 0, -1, 0) -- Where the tween ends

	local TweenInfo = TweenInfo.new(2)

	local Tween1 = TweenService:Create(TextLabel, TweenInfo, {Position = Pos2})
	
	Tween1:Play()
end)

Pos2 sets the UI element off screen if the main is the size of the screen. The -1 is where it sets it off screen. Is this your problem?

You could do

TextLabel:TweenPosition()

It’s the same thing but less lines of code and it’ll probably work

EDIT: You also are referencing the TextLabel’s parent to startergui when you should parent it under playergui

TextLabel.Parent = plr.PlayerGui.Main

So turns out I had left in a part of the script which inserts the textlabel elements into StarterGUI instead of PlayerGUI

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