Hello developers! what I have here is a snippet of my code where essentially, I would like to create a new textlabel “popUp” in a random location on the gui, a typical pop-up gui counter as seen in classic clicker simulators.
Here is my code:
function generate(popUp)
popUp = Instance.new("TextLabel")
popUp.Parent = script.Parent.Parent
popUp.Size = UDim2.new(0, 75, 0, 75)
popUp.BackgroundTransparency = 1
popUp.TextScaled = true
popUp.Font = Enum.Font.AmaticSC
popUp.Text = "+"..multiplier.."click"
local uiCorner = Instance.new("UICorner") -- Creating UI corner for popUp
uiCorner.CornerRadius.Scale = 1
uiCorner.CornerRadius.Offset = 0
uiCorner.Parent = popUp
local uiStroke = Instance.new("UIStroke") -- Creating UI stroke for popUp
uiStroke.LineJoinMode = Enum.LineJoinMode.Round
uiStroke.Color = Color3.fromRGB(0, 0, 0)
uiStroke.Thickness = 1
uiStroke.Parent = popUp
popUp.Visible = true -- Defining popUp tweens
local randomX = math.random(1, 100)
local randomY = math.random(1, 100)
local xVal = randomX/100
tonumber(xVal)
popUp.Position = UDim2.new(xVal/100, 0, randomY/100, 0)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.In) -- Tween popUp
local tweenPop = TweenService:Create(popUp, tweenInfo, {Position = UDim2.new(xVal, 0, 0, -0.1)}, {TextTransparency = 1})
tweenPop:Play()
local tweenStrokeTrans = TweenService:Create(uiStroke, tweenInfo, {Transparency = 1}) -- Tween popUp.UIStroke
tweenStrokeTrans:Play()
task.wait(1.1)
popUp:Destroy()
end
multiple is just a variable that is defaulted at 1
My issues are:
- The most important: I believe ‘xVal’ is a string (?), which is why I tried to convert it to a number since the arguments for UDim2.new has to be numbers. I am not sure if i am able to use variables to substitute numbers? As it wouldn’t work with how I wanted it to be if it wasn’t. What I want to achieve here is to only tween the Y-position of the newly generated ‘popUp’ Instance, and not the X-position altogether.
I am unsure if there are ways to go about this with or without using UDim2.new() to achieve the result of tweening only the y axis here. I tried using UDim() but that doesn’t seem right and did not work.
-
My UICorner syntax might be wrong? I am also unsure of the syntax for UIStroke…If anyone knows anything about it or have the link to the documentation (I couldn’t find or I’m blind…), please help me to correct my code :-;
-
The popUps generates and is stuck in the top left corner without tweening at all, it was working perfectly fine where it generates in a random location of the gui screen, and tweens up through the y axis only. I don’t remember what I did, but I tried to fix the syntax of the UIStroke and UICorner which kind of messed everything up…
It’s been a while since…again, but this time I am currently studying comp sci so I have more knowledge about coding in general now. Thanks for reading…I don’t know how to conclude this…