I am trying to make a ui that shows and dissapears everytime a stat gets added.
the disappearing part is not working, and the ui doesn’t end up in a random location like i intended.
script (main part that isn’t working):
RpS:WaitForChild("GameRemotes"):WaitForChild("Client"):WaitForChild("StatAdd").OnClientEvent:Connect(function(p1, p2)
local StatAddUI = RpS:WaitForChild("GameUIs"):WaitForChild("StatAdd"):Clone()
StatAddUI.Parent = plr:WaitForChild("PlayerGui"):WaitForChild("PlayerMain")
local stat_to_change = StatAddUI:WaitForChild("Stat")
local amount = StatAddUI:WaitForChild("Amount")
StatAddUI.Position = UDim2.new(math.random(0.125, 0.875), 0, math.random(0.125, 0.875), 0)
stat_to_change = p1
amount = tostring(p2)
local TweenInf = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local Goal = {TextTransparency = 1}
local Tween1 = TS:Create(stat_to_change, TweenInf, Goal)
local Tween2 = TS:Create(amount, TweenInf, Goal)
Tween1:Play()
Tween2:Play()
delay(1, function()
StatAddUI:Destroy()
end)
end)
i have tried turning the tweens into a while stat_to_change < 1 do statement, also tried asking in a different place.
edit: tween1 gives a “Unable to cast value to Object” error, the “StatAddUI.Position = UDim2.new(math.random(0.125, 0.875), 0, math.random(0.125, 0.875), 0)” part just doesn’t work, no errors
The function math.random(x, y) returns an integer between [x, y], the interval meaning that x and y are included in the range.
To generate random numbers, you should use Random.new():
local seed = Random.new()
local pos = UDim2.fromScale(seed:NextNumber(0.125, 0.875), seed:NextNumber(0.125, 0.875))
-- UDim2.fromScale is just an easier way to edit a UI element's Scale properties
-- rest of your code
For your first problem, I think the cause of this error is because you’re tweening a string instead of a UIObject. At this part of your code, you equated stat_to_change and amount to p1 and p2 which consequently make them strings:
stat_to_change = p1
amount = tostring(p2)
Hence, when you apply tween to them, it will output an error. I guess what you’re trying to do here is to change the text value of the Stat UI and the amount UI. Try applying these changes and maybe to could help: