Help me with math.random() specifying numbers

I’m sorry for the ugliness of this text earlier.

  1. What do you want to achieve?
    I am making a script where it picks a number 1 or 10

  2. What is the issue?
    I am using math.random(1,10) but it also takes out numbers between them like
    1.5 or 2.4

  3. What solutions have you tried so far?
    I can’t connect to DeveloperHub so please give answers here.

-----------------------------------------------CODE---------------------------------------------------

game.Workspace.started.Changed:Wait()

if game.Workspace.started.Value == true then

function botmovement()

math.randomseed(tick())

game.Workspace.BasedBot.Humanoid:Move(Vector3.new(math.random(0,1),0,math.random(0,1)))

end

end

-----------------------------------------------CODE---------------------------------------------------

My little friend,you were supposed to clear all of these lines,you only would let the

1-What do you want to achieve?
(Insert what do you want to achieve here)

2-What is the issue?
(Insert what is the issue here)

3-What solutions you have tried so far?
(Insert your past tries here)

Besides that,i understood almost nothing,this is very badly explained

Also what??

[30 charsssssssss]

If you’re trying to get the number 1 or 10 at random, then instead of assigning a variable to math.random(1,10) you could assign a global blank variable and then reassign it to have data after conditions are met. In this case, that data would be whether the number is 1 or 10 and the conditions to be met are completely up to you. An example:

local EmptyVariable
local PlaceHolder = 'yes' -- This is here because I'm not fully aware of what you are asking, so I came up with my own thing! :D

if PlaceHolder == 'Yes' then
    EmptyVariable = 1
else
    EmptyVariable = 10
end

It would appear you’re definitely a beginner at Scripting, which is completely fine! This is the most simplistic way I think I would be able to accomplish this sort of task, so hopefully you find this useful in some way. :slight_smile:

but it is being executed multiple times
sorry anyway i just updated the ugly text

That code will not work. You’re iterating through Numbers but in the iteration you’re using a table in math.random() (not valid by the way, math.random takes numbers as the first two args).


Going off of @Tenrous’s solution, I would probably use a math.floor() function (which rounds down) and use math.random(0, 2) so that you get either a 0 or a 1. Then, you can just do

local result = math.floor(math.random(0, 2))
if result == 0 then
    -- code here
else
    -- code here
end

thank u very much, i forgot about that thing!
how to lock thread