Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Getting 1 random number?

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?

2 comments

0

Your question doesn't make sense. Include the full context of how you're using this number.

0

I edited it with the full script.

1 answer

✓ Accepted answer

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.

1 comment

0

Please up vote me I'm trying to make a difference.

This discussion is preserved as it was. New answers, comments, and votes are closed.