So this script actually doesn't randomize the value it just gives me the same all over again. And also how can I make it randomize with a percentage chance?
local example = {"Sung", "Hanma", "Yami"} local randomNum = Random.new() :NextInteger(1, #example) game.Players.PlayerAdded:Connect(function(player) player.Chatted:Connect(function(message) if message == "!reroll" then print(example[randomNum]) end end) end)
Hey lovely developer! This is how i would make it!
local example = {"Sung", "Hanma", "Yami"} local randomNum = 0 game.Players.PlayerAdded:Connect(function(player) player.Chatted:Connect(function(message) if message == "!reroll" then randomNum = math.random(1,#example) print(example[randomNum]) end end) end)
I think doing math.random() is better!
https://developer.roblox.com/en-us/api-reference/lua-docs/math
it will just choose a number between [1,2,3]!
Have a nice day!
You assigned the variable to run the function once, and then use it upon playeradded.
local example = {"Sung", "Hanma", "Yami"} local randomNum -- setting variable game.Players.PlayerAdded:Connect(function(player) player.Chatted:Connect(function(message) if message == "!reroll" then randomNum = math.Random(1,#example) --Randomizes the variable every time its ran print(example[randomNum]) end end) end)
You aren't changing the random number at all. Simply repositioning the line should fix it.
local example = {"Sung", "Hanma", "Yami"} local randomNum = Random.new() game.Players.PlayerAdded:Connect(function(player) player.Chatted:Connect(function(message) if message == "!reroll" then print(example[randomNum:NextInteger(1, #example)]) end end) end)
Edit: Seems like this question was already answered.