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

How come the math.random isn't finding a number between 1 to 40 after lots of tries?

Here's my script;

local part = script.Parent
local activated = false

part.Touched:connect(function()
	print("dirt function started")
	if activated == false then
		activated = true
		print("activated is now true")
		local chance = math.random(1,100)
		print("chance activated")
		if chance > 1 and chance < 40 then
			print("Found something")
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = 0
			game.Players.LocalPlayer.PlayerGui.BattleGuiTest:WaitForChild("IntroTop"):TweenPosition(UDim2.new(0, 0,0, 0),'Out','Bounce',3.5)
			game.Players.LocalPlayer.PlayerGui.BattleGuiTest:WaitForChild("IntroBottom"):TweenPosition(UDim2.new(0, 0,0, 200),'Out','Bounce',3.5)
			wait(5)
			game.Players.LocalPlayer.PlayerGui.BattleGuiTest:WaitForChild("BattleBackGround").Visible = true
			wait(0.5)
			--Might add functions
			game.Players.LocalPlayer.PlayerGui.BattleGuiTest:WaitForChild("IntroTop"):TweenPosition(UDim2.new(0, 0,-1, 0),'In','Bounce',3.5)
			game.Players.LocalPlayer.PlayerGui.BattleGuiTest:WaitForChild("IntroBottom"):TweenPosition(UDim2.new(0, 0,0, 800),'In','Bounce',3.5)
		else
			print("found nothing")
			if activated == true then
				return
			end
		end
	end
end)

No errors but it won't find a number after several tries. Please help!

1 answer

✓ Accepted answer

You are almost certainly testing this in Roblox Studio.

In Roblox Studio, random numbers will be the same on start because the seed does not reset.

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