Math.Random script not working!

  1. What do you want to achieve? I want to know why my script is not working.

  2. What is the issue? It is not working and nothing is being said in the output.

  3. What solutions have you tried so far? I have tried to get ChatGPT to fix the script

-- Function to be called if the random number is 1
function fireFunction()
	print("The random number is 1! Firing the function.")
	game.ServerStorage.Maze.Parent = workspace
end

-- Generate a random number between 1 and 2 (inclusive)
local randomNumber = math.random(1, 2)

-- Display the generated random number
print("Generated random number:", randomNumber)

-- Check if the random number is 1 and call the function if true
if randomNumber == 1 then
	fireFunction()
else
	print("The random number is not 1.")
end


The script is to, when a certain number is picked, a model named maze will appear in the workspace.

Aha! You Did Something Wrong

-- Function to be called if the random number is 1
function fireFunction()
	print("The random number is 1! Firing the function.")
	game.ServerStorage.Maze.Parent = workspace
end

-- Generate a random number between 1 and 2 (inclusive)
local randomNumber = math.random(1, 2)

-- Display the generated random number
print("Generated random number:" ..tostring(randomNumber))

-- Check if the random number is 1 and call the function if true
if randomNumber == 1 then
	fireFunction()
else
	print("The random number is not 1.")
end

Ekran görüntüsü 2024-02-10 110332

Here Is Output

If You Have No Error Mark This Solution

Thank you! I will test the script now.

If You See Not Output Try Using wait(5)

I have tested the script and the maze has not appeared so I will make the range of numbers 1,1

1 Like

Well I Have An Output
Ekran görüntüsü 2024-02-10 110854
Ekran görüntüsü 2024-02-10 111204

1 Like

Also You Put Maze Model Into ServerStorage

1 Like

I tried making the range of numbers 1,1. it is still not working.

1 Like

Nothing wrong with this script … it’s something else.
Ran it a few times got both prints …

Other than the maze not in my program it fired fine on a 1
Is your script enabled?

1 Like

also the maze is supposed to be in the server storage, then go to the workspace.

1 Like

Hmm Let Me Fix That

function fireFunction()
	print("The random number is 1! Firing the function.")
	game.ServerStorage.Maze.Parent = workspace
end

-- Generate a random number between 1 and 2 (inclusive)
local randomNumber = math.random(1, 50)

wait(5)

-- Display the generated random number
print("Generated random number:" ..tostring(randomNumber))

-- Check if the random number is 1 and call the function if true
if randomNumber == 1 then
	fireFunction()
else
	print("The random number is not 1.")
end

Ekran görüntüsü 2024-02-10 111529

1 Like

I will test the script now,

thanks for helping btw!

it is still not working. Do you have any other ideas?

oh if you want see the output go up all way down
for example i cant see because of my plugin but i can see it
Ekran görüntüsü 2024-02-10 111854
or to do this work you need serverscript

1 Like

YES IT WORKS!!!

thank you so much parenting the script to server script service fixed it.

1 Like

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