How would i go about geting a number from a side to side bar?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    i want to get a number from a bar ive made
  2. What is the issue? Include screenshots / videos if possible!
    I dont know where to start
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    ive looked for solutions on the dev hub
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
    I just need a point to launch of please do not give it to me because i m a new game dev learning to make games! here is my Janky script to make it move
    local ButtonUp = false
    local STOP = false
    local FirtUp = true
    script.Parent.MouseButton1Down:Connect(function()
    if ButtonUp == false then
    ButtonUp = true
    else
    STOP = true
    end

end)
script.Parent.MouseButton1Click:Connect(function()
repeat
if FirtUp == false then
if STOP == false then
repeat
wait(0.04)
script.Parent.Parent.PowerDisplay.Position = script.Parent.Parent.PowerDisplay.Position - UDim2.new(0.015,0,0,0)
until script.Parent.Parent.PowerDisplay.Position.X.Scale < 0.49841707944869995 or STOP == true
script.Parent.Spin.Value = script.Parent.Spin.Value - 5
end
else
FirtUp = false
end
if STOP == false then
repeat
wait(0.04)
script.Parent.Parent.PowerDisplay.Position = script.Parent.Parent.PowerDisplay.Position - UDim2.new(0.015,0,0,0)
until script.Parent.Parent.PowerDisplay.Position.X.Scale < 0.35112607479 or STOP == true
end
if STOP == false then
repeat
wait(0.04)
script.Parent.Parent.PowerDisplay.Position = script.Parent.Parent.PowerDisplay.Position + UDim2.new(0.015,0,0,0)
until script.Parent.Parent.PowerDisplay.Position.X.Scale > 0.36040225625 or STOP == true
end
if STOP == false then
repeat
wait(0.04)
script.Parent.Parent.PowerDisplay.Position = script.Parent.Parent.PowerDisplay.Position + UDim2.new(0.015,0,0,0)
until script.Parent.Parent.PowerDisplay.Position.X.Scale > 0.6509760022163 or STOP == true
end
if STOP == true then
print(script.Parent.Spin.Value)
end
wait()
until STOP == true
end)
image
i want the number in the place that says Spin
the bar when you click it starts moving side to side and when you stop it i want the number from where i stoped it
here is a pick the black square moves
image
Thanks for any help again please just give me a place to jump off not a script

1 Like

To determine the position of a button on a bar, we need to calculate its relative position compared to the size and position of the bar.

I’ll be guessing that you’re looking for a value ranging from 0 to 1 (which can easily be converted to percentage).

Let’s assume we have this information:

  • Bar size (X): 50
  • Bar position (X): 500
  • Button position (X): 525

The button would be that black dot in the center of the bar in your image

The formula is essentially:
P = (ButtonAbsolutePositionX-BarAbsolutePositionX)/BarAbsoluteSizeX

Basically, P = (525-500)/50 → 0.5


You could also just use script.Parent.Parent.PowerDisplay.Position.X.Scale. That should do the job. I think?

Thank you so much! thats a big help and script.Parent.parent.Powerdisplay.Position.X.Scale should work
for the button thanks so much again your a life saver
im gona go hop into studio and see if i can get it to work

also FYI the text button itself is invisible to get if you click without changing the color of things

Thanks so much it works 1 thing whats it the difference between P = Whatever and local P = Whatever
besides that im new how would i mark the solution and is there a way i could give you like a good rating or something you gave just enuff for me to get it witch is what i wanted! (This is my fist topic btw.)

I’m glad to know that it worked!

I only said P = equation in the message to demonstrate an equation and what it could return.
For your case, in your code it would be preferably you define it as a local variable just so the different threads don’t get confused on which P is assigned to them.
That is if you need a variable for it. If not, you could just directly insert the equation (e.g., label.Text = equation).

I’m not sure if I explained that well, and I think you’re asking about something else so here’s another quick explanation.

for _ = 1, 10 do
    print(P)
    P = math.random(1, 10)
end
for _ = 1, 10 do
    print(P)
    local P = math.random(1, 10)
end

You’ll notice that the code #1 first prints nil then prints random while in the 2nd it’s always nil. local variables are only able to be accessed within their scope (essentially in their indented area).


Nice first post btw. You could just press that Solution button next to the heart button. It should look like this.
image

I appreciate the thought of you giving me a Solution.

Again ty so much man tour a big lif savor

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