I want to make a RNG Game where you get (fake rbx) for rolling. But I don’t know how to make a RNG and this is how far I could get.
(ServerScriptService Script)
local r = game.ReplicatedStorage.Events
r.Roll.OnServerEvent:Connect(function(plr)
plr.leaderstats["🎲 Rolls"].Value += 1
local luck = math.random(1, 1000)
game.StarterGui.Game.RollingFrame.Visible = true
game.StarterGui.Game.RollingFrame.Chance.Text = tostring(luck).." in 1,000"
game.StarterGui.Game.RollingFrame.Amount.Text = plr.Values.Base * luck
end)
I also want to show the “1 in ???” on the fifth number.
This is my leaderstats:
So hey there!
I see that you got stuck on this problem just like me. Weeeellll heres a tutorial or concept video I dug up and found:
This video has a basic understanding of RNGs and like actually creates a well organized way with the types of “rolls” you can get. There is also another post that I made a long time ago about this might wanna check that out (probably not gonna help you compared to the vid):
I’m unsure, but maybe you could assign a certain amount of numbers to each outcome for it to work? Like you could have it so 1, 2, 3, 4 and 5 would be a 5/1000 chance?
Also, you could create a variable outside of the function for amount of rolls and set it to 0 or nil. Then each time you roll, you increase it by 1. Then you use an if statement to check if it’s 5. Then you can reset it and create an invisible text label or use instance.new.
This video is long, but what part of the video to when is it talking about RNG? Are they talking about the RNG for the whole video? I might watch this tomorrow but if you can explain that a little more then I don’t have to watch the whole part.
From the 5 minute mark to the 12:35 approx. is the main section. (Sry lol for not explaining correctly)
If you watch a minute before the 5 it like shows the “template” thingy for your rng rolls but really other than that not rly anything important. A small application of the rng is used after 12:35.
Now I have an error: ServerScriptService.RollHandler:12: attempt to perform arithmetic (mul) on nil and number
Script is here, index is producing the error:
r.Roll.OnServerEvent:Connect(function(plr)
plr.leaderstats["🎲 Rolls"].Value += 0
local luck = 1
for i = 1, 5 do
local index = RarityService.chooseIndex(Rarities, luck)
if i == 5 then
print("Chosen rarity: "..index)
plr.Values.Robux.Value += (tonumber(index) * plr.Values.Base.Value) -- Error Line
else
print("Possible rarity: "..index)
end
wait(1)
end
--game.StarterGui.Game.RollingFrame.Visible = true
--game.StarterGui.Game.RollingFrame.Chance.Text = "1 in "..tonumber(index[2])
--game.StarterGui.Game.RollingFrame.Amount.Text = plr.Values.Base * luck
end)
I’m pretty sure you got confused with what you write but you’re currently trying to convert a string (index) into a number with tonumber, which is not possible.