Hello!
I want to create a Roblox probability calculator. You enter the probability in % and then it says what is the answer YES or NO Can you help me to make it? I tried to use math.random() but it didn’t work well.
this is the script I made
script.Parent.MouseButton1Click:Connect(function()
local percent = math.random(script.Parent.Parent.Value.Value,100)
if percent == 100 then
script.Parent.Parent.TextLabel.Text = "Yes"
else
script.Parent.Parent.TextLabel.Text = "No"
end
end)
here is a screen shot of the game:

You can get the probability in % then convert it to 0 - 1
, then do math.random()
, if the result is higher than the specified number then it’s a YES, if it’s lower then it’s a NO
For example:
> Input 30%
> Convert it to 0.3
> Do math.random(), returns 0.626
> Return YES
> Do math.random() again, returns 0.215
> Return NO
U didnt explain the problem really well tbh, but anyways this is how I imagine ur problem: for example if I write in 50% then ther is a 50% chance of printing yes and 50% printing no.
So thats how u do it:
local chance = 70
local randomNum = math.random(1, 100)
if randomNum <= chance then
print("yes")
else
print("no")
thx it worked
oof oof i need 30 сhаrасtеrѕ
1 Like