Hello, I have been trying to make a level system for a small game that I am making, and it works pretty well until you start gaining xp too fast. If you start gaining too fast then the xpbar progress will appear inaccurate with the amount of xp that you have. I figured out that it probably has something to do with the tween that makes the xpbar go up, but because I haven’t used tweens that ofter I couldn’t figure out what the problem is.
I had a similar problem with a health bar GUI. I was able to simplify it and solve it, but it wouldn’t be able to solve your problem.
What i would try here is check if a tween is in progress and if it is, wait until that tween has finished (Tween.Finished
) and then play the next tween
Yeah I was thinking of that as well, but it doesn’t work for Tweensize I think sadly.
So why don’t you just tween the size with TweenService:Create
?
You can tween size and really any other tweenable property with that methods
I dont really know how to convert what I currently did into that method, but I am trying to figure it out rn
local Player = game.Players.localPlayer
local TweenService = game:GetService("TweenService")
local PlayerXp = Player:WaitForChild("PlayerXp")
local maxxp = 100
PlayerXp.Changed:Connect(function(Changed)
if Changed then
local targetSize = UDim2.new(PlayerXp.Value/100, 0,1,0)
local tweenInfo = TweenInfo.new()
local tween = TweenService:Create(script.Parent.ExpBar, tweenInfo, {Size = targetSize})
tween:Play()
end
end)
while wait() do
script.Parent.XpLabel.Text = PlayerXp.Value.."/".. 100
end
This seems to work now, and to my surprise I don’t even have to check if the current tween is still playing. I guess this method of doing it is more reliable. Thx for helping me to figure it out:))
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.