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?
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