1

# How do I make something happen when a certain random number is generated?

I'm trying to make a script to where when a certain number is randomly generated it spawns a zombie. I hope someone could help me out!

game.Players.PlayerAdded:Connect(function()

local ServStoarge = game:GetService('ServerStorage')
local Zombie = ServStoarge.Zombie

local Spawner = game.Workspace.Spawner

while true do

print(math.random(1, 5))

if math.random == 1 then

Zombie:Clone()

Zombie.HumanoidRootPart.CFrame = game.Workspace.Spawner.CFrame + Vector3.new(0, 2, 0)

end

end
end)


0
Hypoxla 125
22 days ago

The problem is the random number you generated with math.random(1,5) is not stored anywhere, it is just printed.

You tried using if math.random == 1 but the random number you generated before was not stored.

Instead, you can check it in the if statement:

    if math.random(1,5) == 1 then

Zombie:Clone()

Zombie.HumanoidRootPart.CFrame = game.Workspace.Spawner.CFrame + Vector3.new(0, 2, 0)

end


If any errors appear or it doesn't work, let me know.

0
Oh hey that works! thanks man :D I'm newer to scripting I used to do modeling so this is a big help even if it is just some reorganization. Have a great day or night and thanks for the help :) xxXDuckzzXxx 15 — 22d