Hello! So I have this level gui. My problem is that the bar goes outside the frame. Here’s my local script in the gui:
local Player = game.Players.LocalPlayer
local XP = Player.XP
local RequiredXP = Player.RequiredXP
script.Parent.XPBar:TweenSize(UDim2.new(XP.Value/RequiredXP.Value, 0,1,0))
XP.Changed:Connect(function(changed)
if changed then
script.Parent.XPBar:TweenSize(UDim2.new(XP.Value/RequiredXP.Value, 0,1,0))
end
end)
while wait() do
script.Parent.XPLabel.Text = XP.Value.."/"..RequiredXP.Value
end
And here’s a part of a leaderstats and data store script i used for my level gui:
local level = Instance.new("NumberValue")
level.Name = "Level"
level.Parent = leaderstats
level.Value = 1
local XP = Instance.new("NumberValue")
XP.Name = "XP"
XP.Parent = player
XP.Value = 0
local RequiredXP = Instance.new("NumberValue", player)
RequiredXP.Name = "RequiredXP"
RequiredXP.Value = level.Value*100
XP.Changed:Connect(function(changed)
if XP.Value >= RequiredXP.Value or XP.Value == RequiredXP.Value then
XP.Value = 0
level.Value += 1
RequiredXP.Value = level.Value*100
end
end)
Somehow, I’m not getting any errors or warnings from it but nothing happens. Is there any solution to this?
There is virtually no difference in your script other than you removing the while wait do loop and moving the line into the changed event, aswell as doing some longer typing (
Which is the same as RequiredXP.Changed
BTW, not sure if it was in purpose or not but, he used XP.Changed not RequiredXP.Changed
I used RequiredXP:GetPropertyChangedSignal(“Value”) because when the XP changes, it takes a split second for the RequiredXP to change so it might put the wrong RequiredXP if we use XP.Changed instead of RequiredXP.Changed
This would be true for any case other than an “ValueInstance” (ex. StringValue, IntValue, etc), there is a special rule for “ValueInstances” that the .Changed method is only for .Value