Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

So i need a chance system for a random number picker any ideas?

Asked by 3 years ago
    local BrickEvent = game.ReplicatedStorage.Events.Gui

    BrickEvent.OnClientEvent:Connect(function(plr)
local num = math.random(1,3)
    if num == 1 then
              print("you got Critical Hit Fact")
            script.Parent.ScreenGui.Frame.HintCriticalDamage.Visible=true

     elseif num == 2 then
             print("you got Stamina Fact")
            script.Parent.ScreenGui.Frame.HintStamina.Visible=true
     elseif num == 3 then
             print("you got Jump Attack Fact")
            script.Parent.ScreenGui.Frame.HintJump.Visible=true

                end
    wait("9")
            script.Parent.ScreenGui.Frame.HintCriticalDamage.Visible=false
            script.Parent.ScreenGui.Frame.HintStamina.Visible=false
            script.Parent.ScreenGui.Frame.HintJump.Visible=false
        end)

that's my code and almost every time i get the same one twice in a row is there any way I can add a chance system so it almost never gets the same one in a tow

3 answers

Log in to vote
0
Answered by
rabbi99 714 Moderation Voter
3 years ago

Maybe this works

local BrickEvent = game.ReplicatedStorage.Events.Gui

local hadnum1once = false
local hadnum2once = false
local hadnum3once = false

BrickEvent.OnClientEvent:Connect(function(plr)
    local num = math.random(1,3)
    if num == 1 and hadnum1once == false then
            print("you got Critical Hit Fact")
            hadnum1once = true
            script.Parent.ScreenGui.Frame.HintCriticalDamage.Visible = true
     elseif num == 2 and hadnum2once == false then
            print("you got Stamina Fact")
            hadnum2once = true
            script.Parent.ScreenGui.Frame.HintStamina.Visible = true
     elseif num == 3 and hadnum3once == false then
            print("you got Jump Attack Fact")
            hadnum3once = true
            script.Parent.ScreenGui.Frame.HintJump.Visible = true
     elseif num == 1 and hadnum1once == true then
            print("you got Jump Attack Fact")
            hadnum1once = false
            hadnum3once = true
            script.Parent.ScreenGui.Frame.HintJump.Visible = true
     elseif num == 2 and hadnum2once == true then
            hadnum2once = false
            hadnum1once = true
            print("you got Critical Hit Fact")
            script.Parent.ScreenGui.Frame.HintCriticalDamage.Visible = true
     elseif num == 3 and hadnum3once == true then
            print("you got Stamina Fact")
            hadnum1once = true
            hadnum3once = false
            script.Parent.ScreenGui.Frame.HintStamina.Visible = true


    end
            wait(9)
            script.Parent.ScreenGui.Frame.HintCriticalDamage.Visible=false
            script.Parent.ScreenGui.Frame.HintStamina.Visible=false
            script.Parent.ScreenGui.Frame.HintJump.Visible=false
        end)
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

you can do

local previousnum
if previousenum ~= num
    then do the code if it is diffrent
end
previousnum = num

so putting it in your script it would be



local BrickEvent = game.ReplicatedStorage.Events.Gui local prevnum BrickEvent.OnClientEvent:Connect(function(plr) local num = math.random(1,3) if prevnum ~= num then if num == 1 then print("you got Critical Hit Fact") script.Parent.ScreenGui.Frame.HintCriticalDamage.Visible=true elseif num == 2 then print("you got Stamina Fact") script.Parent.ScreenGui.Frame.HintStamina.Visible=true elseif num == 3 then print("you got Jump Attack Fact") script.Parent.ScreenGui.Frame.HintJump.Visible=true end wait("9") script.Parent.ScreenGui.Frame.HintCriticalDamage.Visible=false script.Parent.ScreenGui.Frame.HintStamina.Visible=false script.Parent.ScreenGui.Frame.HintJump.Visible=false end) prevnum = num end end
0
where do i put that in the script? TheMiniMagic_YT 27 — 3y
0
so i tried your code and i get a error TheMiniMagic_YT 27 — 3y
0
ok changed your script botw_legend 502 — 3y
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

The problem lies within the nature of the math.random function. How it works is that it generates a value from x to y, with the 'seed' of the RNG (Random Number Generator) determining the outcome. Since you haven't set the seed to anything it'll spit out the same sequence every time.

To set the seed you simply use the math.randomseed function, with the only argument being the seed.

To make your script truly randomized you can just slap this line of code onto the top lines of your script, just make sure that you set the seed before you need to generate a random number.

math.randomseed(tick())

The tick function returns the timepoint at which it was called, meaning that it will be different each time it is called. Which is perfect for an RNG seed.

Answer this question