How do i count up by 10s from a number? [ easy solution for you, just answer it ]

ok so imagine like
i have a weight system and i want to count up by 10s

current weight: 105
how do i count that up by tens?

if my current weight is 105 and i count by 10’s ill get 10, ten’s, but how do i count up by that tho? tostring or something?

3 Likes
weight += 10

(Probably what you’d do normally when changing it)

Or in a loop:

for i = start, stop, 10 do
    --do something here
end
2 Likes

is there a more efficient way without needing a loop?

What context is this in? How would a player gain the weight?

picking up a item that has weight, the weight can be of any number really, i just want to count up by 10’s to see how much walkspeed i have to subtract

Just use .touched and then add the weight?

When they touch the item, they gain 10 weight?

-- where 'weight' is the variable holding the weight
weight += 10

Just add this to the function connected to the.Touched event.

@12345koip No im saying like, The player picks up a tool that has a defined weight value in it,
The weight value goes to this script, This script counts up by 10 FROM the weight, 10, 20, 30 (etc) until theres no more 10’s to count. After this it gives me a variable of how many times it counted up from 10.

So you say it should stop at 100?

That was confusing to understand. Is this what you want?

math.floor(weight / 10)

1 Like

To achieve this you’d want something like this:

humanoid.WalkSpeed = baseWalkSpeed - math.floor(weight / 10)

baseWalkSpeed being whatever you want the walkspeed to be at 0 weight.

Have an IntValue inside the weight object holding how many it has.

Then:

local weight =  -- path to your weight
local weightIntValue = weight:WaitForChild("IntValue")

local weightValue = weightIntValue.Value --the value that will increase by 10

Then, when you want it to count up from the weight, just do the line:

weightValue += 10

This will basically create a new variable with a starting value that of the weight. Then, adding 10 to that variable will mean you can have a variable to hold the weight + amount without editing the original value (which is the IntValue).

You could implement this inside a function so it will change on a certain event, like picking up a new weight.

If you change the name of the IntValue, remember to also change the name of it in the WaitForChild() function.

very gaming of you, loudbytes. very gamiing.

1 Like

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