Wait(math.random()) isn't working

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

  1. What do you want to achieve? I’ve made this flying pigeon that lays explosive eggs don’t ask why.

  2. What is the issue? It was working until I changed out the “while wait(1) do” for a while “wait(math.random(0.6, 1.2))”
    now for some reason it lays like 4 eggs at a time

Video of the pigeon laying a bunch of eggs
robloxapp-20250115-1732336.wmv (3.9 MB)

  1. What solutions have you tried so far? I tried seeing if maybe the egg was the problem which it wasn’t so I am assuming it is something wrong with the script

The pigeon also tweens to random positions so that may be the problem but I doubt it is

while wait(math.random(0.6, 1.2)) do
	
	eggClone = game.ServerStorage.egg:Clone()
	eggClone.Parent = workspace
	eggClone.Position = game.Workspace.Pigeon.PrimaryPart.Position
	
end

Not sure if this will make a difference, but I think math.random(x, y) returns an integer, so to solve this maybe try

wait(math.random(6,12) * 0.1)

I also suggest using task.wait().

2 Likes

Wierd problem, no idea how to fix this but worst case scenario just use:

while true do
	
	eggClone = game.ServerStorage.egg:Clone()
	eggClone.Parent = workspace
	eggClone.Position = game.Workspace.Pigeon.PrimaryPart.Position
	
	task.wait(math.random(0.6, 1.2))
end

Ok, yeah just use the thing @h_geen posted

1 Like

It worked!
Now my pigeon can lay eggs peacefully.

1 Like

math.random() only returns whole numbers, so you can multiply by a decimal like 0.1, I also recommend doing task.wait(…).

2 Likes

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