Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Getting 1 random number?

Asked by 8 years ago
for i,v in pairs(game.Workspace:GetChildren()) do
    if v.Name == "Lava" or v.Name == "TeleportPad" then
        v.Touched:connect(function(hit)
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if player ~= nil then
                local number = math.random(1, 5)
                if number == 1 then
                    ad = script.RunAd:Clone()
                    ad.Parent = player.PlayerGui
                    ad.Disabled = false
                end
            end
        end)
    end
end

I want this to get just 1 random number, between numbers 1 - 5, but it gives out lik 10 numbers, for example 2, 5, 3, 3, 3, 2, 4, 1, 2, 5 How can I get it so it just gives 1 random number?

0
Your question doesn't make sense. Include the full context of how you're using this number. BlueTaslem 18071 — 8y
0
I edited it with the full script. NinjoOnline 1146 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Well its giving a random number more then one time because your math.random() is inside a loop. Since its 10 times I'll assume there's ten objects in Workspace(you're looping through the number of objects inside Workspace right?)

If you just want it to give 1 random number once put

local number = math.random(1,5)

But remember to remove line 6 first before doing that. I hope I got it right.

Your welcome.

0
Please up vote me I'm trying to make a difference. OMEGA27304 8 — 8y
Ad

Answer this question