Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make the X axis move along with my IntValue?

The script is supposed to make the X axis move based on the value of my IntValue


-- [Player Related Variables] --
local player = game.Players.LocalPlayer
local level = player:WaitForChild("Level")
local current = level:WaitForChild("Current")
local max = level:WaitForChild("Max")

-- [UI Related Variables] --
local gui = script.Parent
local LevelFrame = gui:WaitForChild("Level Frame")
local label = LevelFrame:WaitForChild("LVL")
local exp = LevelFrame:WaitForChild("Exp Number")
local bar = LevelFrame:WaitForChild("Frame")

--[Changing Player Stats]--
label.Text = "Level "..level.Value
exp.Text = current.Value.."/"..max.Value.." EXP" 
bar.Size = UDim2.new(current.Value/max.Value, 0, 1, 0)

level.Changed:Connect(function(val)
	label.Text = "Level "..level.Value
	exp.Text = current.Value.."/"..max.Value.." EXP"
	bar.Size = UDim2.new(current.Value/max.Value, 0, 1, 0)
end)

level.Changed:Connect(function(val)
	exp.Text = current.Value.."/"..max.Value.." EXP"
	bar.Size = UDim2.new(current.Value/max.Value, 0, 0, 0)
end)

1 answer

I might be wrong but you can try this.

I am also confused as to why you have 2 .changed events for the level...

-- [Player Related Variables] --
local player = game.Players.LocalPlayer
local level = player:WaitForChild("Level")
local current = level:WaitForChild("Current")
local max = level:WaitForChild("Max")
-- [UI Related Variables] --
local gui = script.Parent
local LevelFrame = gui:WaitForChild("Level Frame")
local label = LevelFrame:WaitForChild("LVL")
local exp = LevelFrame:WaitForChild("Exp Number")
local bar = LevelFrame:WaitForChild("Frame")
-- [Changing Player Stats] --
local formula = current.Value / max.Value
label.Text = "Level " .. level.Value
exp.Text = current.Value .. "/" .. max.Value .. " EXP"
bar:TweenSize(UDim2.new(formula, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0, true)

level.Changed:Connect(function(val)
    local formulaNew = current.Value / max.Value
    label.Text = "Level " .. level.Value
    exp.Text = current.Value .. "/" .. max.Value .. " EXP"
    bar:TweenSize(UDim2.new(formulaNew, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.5, true)
end)

Let me know if there are any issues, will try to fix immediately!

2 comments

0

I honestly think if you just get rid of the second level.changed event your script will just work. The tweensize should just make it look better!

0

tightanfall, the script you posted didn't work, the x axis still wouldn't move

This discussion is preserved as it was. New answers, comments, and votes are closed.