How can I add UI Corners to a script?

Hello, I’ve got this script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local rewardEvent = ReplicatedStorage:WaitForChild("CoinRewardEvent")

local SOUND_ID = "rbxassetid://1210852193" 

local function showRewardMessage(coins)

	local screenGui = Instance.new("ScreenGui")
	screenGui.Name = "CoinRewardGui"
	screenGui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")

	local textLabel = Instance.new("TextLabel")
	textLabel.Size = UDim2.new(0.3, 0, 0.1, 0) -- 30% width, 10% height
	textLabel.Position = UDim2.new(0.35, 0, 0.4, 0) -- Centered horizontally
	textLabel.BackgroundColor3 = Color3.fromRGB(85, 255, 127)
	textLabel.TextColor3 = Color3.new(1, 1, 1)
	textLabel.Font = Enum.Font.FredokaOne
	textLabel.TextScaled = true
	textLabel.Text = "You earned " .. coins .. " Coins because you've been playing for 10 minutes!"
	textLabel.Parent = screenGui
	
	textLabel:TweenPosition(UDim2.new(0,0,1,0), "InOut", "Quad",3.5)
	

	local sound = Instance.new("Sound")
	sound.SoundId = SOUND_ID
	sound.Volume = 1
	sound.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")
	sound:Play()

	task.wait(3)
	for i = 1, 20 do
		textLabel.TextTransparency = i * 0.05
		task.wait(0.05)
	end

	screenGui:Destroy()
	sound:Destroy()
end

rewardEvent.OnClientEvent:Connect(showRewardMessage)

I would like to add UI Corners to make the text look nicer, but I cannot seem to find a way to do it in any documentation, and then I’d like to have a smooth tween animation that makes the button pop up at the center top of the screen for 5 seconds and then go back up again but I cannot seem to make it work.

I’d like some help in doing those tasks.
Thanks in advance!

2 Likes

u cant add ui corners to a script, if u want something else, im confused

1 Like

UICorner is an Instance…

local uiCorner = Instance.new("UICorner")
uiCorner.CornerRadius = UDim.new(0, 20)
uiCorner.Parent = frame

Just create one and drop it in.

This is how you would do it:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local rewardEvent = ReplicatedStorage:WaitForChild("CoinRewardEvent")

local SOUND_ID = "rbxassetid://1210852193" 

local function showRewardMessage(coins)

local screenGui = Instance.new("ScreenGui")
	screenGui.Name = "CoinRewardGui"
	screenGui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")

	local textLabel = Instance.new("TextLabel")
	textLabel.Size = UDim2.new(0.3, 0, 0.1, 0) -- 30% width, 10% height
	textLabel.Position = UDim2.new(0.353, 0, 0.014, 0) -- Centered horizontally, Changed X Position to the middle and left a small gap from the top of the screen
	textLabel.BackgroundColor3 = Color3.fromRGB(85, 255, 127)
	textLabel.TextColor3 = Color3.new(1, 1, 1)
	textLabel.Font = Enum.Font.FredokaOne
	textLabel.TextScaled = true
	textLabel.Text = "You earned " .. coins .. " Coins because you've been playing for 10 minutes!"
	textLabel.Parent = screenGui

	local uiCorner = Instance.new("UICorner") -- We create a UI Corner Instance
	uiCorner.Parent = textLabel
	uiCorner.CornerRadius = UDim.new(0.1, 0) -- Set the properties (Scale, Offset fyi)

	textLabel:TweenPosition(UDim2.new(0.353,0,1,0), "InOut", "Quad",3.5) -- Tween it (I changed the X position to the middle)


	local sound = Instance.new("Sound")
	sound.SoundId = SOUND_ID
	sound.Volume = 1
	sound.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")
	sound:Play()


	task.wait(3)
	for i = 1, 20 do
		textLabel.TextTransparency = i * 0.05
		task.wait(0.05)
	end

	screenGui:Destroy()
	sound:Destroy()
end

rewardEvent.OnClientEvent:Connect(showRewardMessage)

Let me know if there’s anything else! I also left comments just so you know what I changed :smiley:

1 Like

Thank you for the script! How can I make it pop up from the top and then stop there for 5 seconds and go back up?

1 Like

Hope this is what you are looking for! (P.S, mark as solution if that’s the case :smiley: )

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local rewardEvent = ReplicatedStorage:WaitForChild("CoinRewardEvent")

local SOUND_ID = "rbxassetid://1210852193" 

local function showRewardMessage(coins)
	local screenGui = Instance.new("ScreenGui")
	screenGui.Name = "CoinRewardGui"
	screenGui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")

	local textLabel = Instance.new("TextLabel")
	textLabel.Size = UDim2.new(0.3, 0, 0.1, 0) -- 30% width, 10% height
	textLabel.Position = UDim2.new(0.353, 0, -0.5, 0) -- Centered horizontally, Changed X Position to the middle and made it so it's off the screen
	textLabel.BackgroundColor3 = Color3.fromRGB(85, 255, 127)
	textLabel.TextColor3 = Color3.new(1, 1, 1)
	textLabel.Font = Enum.Font.FredokaOne
	textLabel.TextScaled = true
	textLabel.Text = "You earned " .. coins .. " Coins because you've been playing for 10 minutes!"
	textLabel.Parent = screenGui

	local uiCorner = Instance.new("UICorner") -- We create a UI Corner Instance
	uiCorner.Parent = textLabel
	uiCorner.CornerRadius = UDim.new(0.1, 0) -- Set the properties (Scale, Offset fyi)

	local sound = Instance.new("Sound")
	sound.SoundId = SOUND_ID
	sound.Volume = 1
	sound.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")
	sound:Play()
	
	
	textLabel:TweenPosition(UDim2.new(0.353,0,0.014,0), "InOut", "Quad",0.8) -- Tween it, the "pop in" tween
	task.wait(5)
	textLabel:TweenPosition(UDim2.new(0.353,0,-0.5,0), "InOut", "Quad",0.8) -- Tween it, the "pop out" tween

	local textTween = TweenService:Create(textLabel, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.In)) -- Instead of your for loop, I replaced it with a tween =)
	textTween:Play()
	textTween.Completed:Wait()

	screenGui:Destroy()
	sound:Destroy()
end

rewardEvent.OnClientEvent:Connect(showRewardMessage)

Ui corner is not an porpety of an text lqbe or frame its an instance

Local UiCorner = instance.new(“UiCorner”)
UiCorner.Parent = textlable