UI Takes too long to appear using UDim2

Hey guys
I wanna make a UI that disappears slides out of the screen whenever the player has 0 of a certain stat, and when he starts earning back this stat, the UI appears again. Here is my script:

local leaderstats = game.Players.LocalPlayer:FindFirstChild("leaderstats")

MultiVariable = script.Parent.Parent.Parent.Parent.Multi

while wait(0.01) do
	if leaderstats.Multiplier.Value <= 0 then
		MultiVariable:TweenPosition(UDim2.new(-0.15, 0, 0.217, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear)
	else
		MultiVariable.Position = UDim2.new(0.009, 0, 0.217, 0)
	end
end

The slide effect is working perfectly but when the player gains the “Multiplier” stat, it takes about half a second for the frame to appear. I don’t know if it’s understandable, if you want, I can do a video showing what I mean.

Thanks
Xera

Try changing you while wait 0.01 to a renderstepped event.
https://create.roblox.com/docs/reference/engine/classes/RunService

Sure thing, i’ve read the article but I didn’t understand anything… How could I use it in my script?

Anything with a continuous wait() function is wrong.

With Values use Changed:Connect to connect any change in its value to a message:

local leaderstats = game.Players.LocalPlayer:FindFirstChild("leaderstats");
MultiVariable = script.Parent.Parent.Parent.Parent.Multi;

leaderstats.Multiplier.Changed:Connect(function(newval)
	if newval <= 0 then
		MultiVariable:TweenPosition(UDim2.new(-0.15, 0, 0.217, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear)
	else
		MultiVariable.Position = UDim2.new(0.009, 0, 0.217, 0)
	end
end)

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