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

math.random() not random?

The problem is it gets stuck on the repeat meaning the until condition isn't being met. There is multiple topics in the data.Topics table.

math.randomseed(os.time()) math.random() math.random() math.random()
function m.ChooseTopic(oldtopic)
	local topic
	if oldtopic then
		repeat
			wait()
			topic = data.Topics[math.random(1, #data.Topics)]
		until not topic == oldtopic
	else
		topic = data.Topics[math.random(1, #data.Topics)]
	end
	return topic --script doesn't get this far
end

How can I make math.random be random?

3 comments

1

Where is your connection line?

1

It's being fired in a different spot, I can assure you though that that is not the problem :/

0

"not" can usually be used in place of ~= But the problem is the not operator has higher precedence than all operators other than ^. So you need to use parentheses to fix this.

1 answer

✓ Accepted answer

The problem is your incorrect use of the not operator.

not topic == oldtopic

evaluates to:

(not topic) == oldtopic 
---which equals
false == oldtopic 
--which is never true

So to fix:

not (topic == oldtopic)
--Or
topic ~= oldtopic

1 comment

0

All this time I thought Not and ~= were interchangeable. This has never failed me before but wow thanks!

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