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

math.random picks the same option everytime?

I am working on a custom loading screen and I wanted to have variety in the text of the loading screen because the same thing would be boring so I came up with this and for some reason the math.random on line 9 picks option 2 over and over and if I add a 3rd option it still picks number 2.

Heres some extra info -

Its under ReplicatedFirst, its a Local Script, and I dont really know anything else to say.

local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
PlayerGui:SetTopbarTransparency(0)

local screen = Instance.new("ScreenGui")
screen.Parent = PlayerGui

local textLabel = Instance.new("TextLabel")

local num = math.random(1,2)
	if num == 1 then
		LoadingText = "Loading"
		textLabel.BorderSizePixel = 0
		textLabel.Size = UDim2.new(1, 0, 1, 0)
		textLabel.Font = "Garamond"
		textLabel.FontSize = Enum.FontSize.Size28
		textLabel.Parent = screen
		
	elseif num == 2 then
		LoadingText = "Beep"
		textLabel.BorderSizePixel = 0
		textLabel.Size = UDim2.new(1, 0, 1, 0)
		textLabel.Font = "Garamond"
		textLabel.FontSize = Enum.FontSize.Size28
		textLabel.Parent = screen
end


local textLabel2 = Instance.new("TextLabel")
textLabel2.Text = "I wonder what game hint will go here?"
textLabel2.BorderSizePixel = 0
textLabel2.Size = UDim2.new(1, 0, .25, 0)
textLabel2.Position = UDim2.new(0, 0, .55, 0)
textLabel2.Font = "Garamond"
textLabel2.FontSize = Enum.FontSize.Size28
textLabel2.Parent = screen

script.Parent:RemoveDefaultLoadingScreen()

local count = 0
local start = tick()
while tick() - start < 6 do
	textLabel.Text = LoadingText .. string.rep(".", count)
	count = (count + 1) % 4
	wait(.5)
end

screen.Enabled = false

Thanks for your time :)

1 answer

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