I’m trying to make an XP bar, but I’m not able to convert the % of the XP out of the MaxXP, into a % of the X on the GUI. I was able to do this with a health bar, but I am struggling with this. The X scale of the GUI is .9.
Local Script:
local MaxXP = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("MaxXP")
local XP = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("XP")
local BlueGui = script.Parent.Blue
print(game:IsLoaded())
while wait() do
local PercentXP = XP.Value/(MaxXP.Value * .9)--This is what I need fixed
BlueGui:TweenSize(
UDim2.fromScale(PercentXP,.05),
Enum.EasingDirection.Out,
Enum.EasingStyle.Quad,
.5,
true
)
end
Server Script:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("IntValue",player)
leaderstats.Name = "leaderstats"
local MaxXP = Instance.new("IntValue",leaderstats)
MaxXP.Name = "MaxXP"
MaxXP.Value = 10
local XP = Instance.new("IntValue",leaderstats)
XP.Name = "XP"
XP.Value = 0
local Level = Instance.new("IntValue",leaderstats)
Level.Name = "Level"
Level.Value = 0
while wait() do
if XP.Value >= MaxXP.Value then
MaxXP.Value = MaxXP.Value + 1
Level.Value = Level.Value + 1
XP.Value = 0
end
end
end)
local Children = game.Workspace:GetChildren()
for i, child in pairs(Children) do
if child.Name == "Part" then
child.Touched:Connect(function(part)
local success,errormessage = pcall(function()
local player = game.Players:GetPlayerFromCharacter(part.Parent)
player.leaderstats.XP.Value = player.leaderstats.XP.Value + 1
child:Destroy()
end)
end)
end
end