Reduce events fired on Reroll System

I was making a reroll system for my game, the player presses a button on the gui and it rerolls, my problem right now is that for each reroll the player does it fires a event to the server which for now means that if I have 1000 rerolls to do it fires 1000 events, is there any way to better implement this or reduce the number of events being fired?

My system does one reroll at a time and I didn’t want to change that, how do other games implement systems like that without firing hundreds of events and lagging the game?

1 Like

Is this for quick rerolls in succession? And is it simply picking a random stat such as a species/magic type at the beginning of an RPG game where your assigned something entirely random?

I think that I have a solution for you, but ideally I’d like to know what “rolling” entails. Is it a slot machine? etc

1 Like

you could have the server accept an extra parameter like ‘rolls’ that has a default value of 1. Your existing code then wouldn’t need to be updated since the default is 1 already, and now you could add it to events to tell the server it needs to do n amount of rerolls in bulk, and you can then just return the result of those rolls in bulk aswell in tables.

1 Like

Yes like the player spamming the button, “rolling” for example a modifier on a weapon

The things is that I only want “single” rolls at each time you solution would work if I wanted something like “do x amount of rolls” but right now I only want single spammeable rolls.

Have a really small denounce, but I don’t think ur solution would cause too much problems for performance, just send little information through the remote event

Thanks, but what does sending little information mean? Less data?

Ok, new idea: you could have a request queue, whenever the player rolls a request is added to the queue, and when the queue is emptied you can send one remote event with all of the requests in the queue and calculate the rolls in bulk.

Here’s the trick

Step #1: You’ll want to save a value for each player, this value will be the iteration of their randomized stat. This will make sense later, but for now just assign the value to 0. This will be used instead of saving the actual “rolled modifier”

Additionally, if you’re implementing multiple weapons into your game and want them to always be random you can implement certain randomization to each one. This will make more sense later.

Tool.ModifierRandomization = math.random(1, os.time())
Tool.ModifierIteration = 0

Step #2: Within your reroll code on the client, you’ll essentially want to predict and randomize the enchant ENTIRELY on the client & server simultaneously! We’ll be able to do this with Random.new()

On the client, you’ll iterate up this ModifierIteration for every reroll that you do.

Once you do that, a function can be ran which iterates +1 on your random.

local RNG = Random.new(ModifierRandomization)
local Iteration = 0

local function Reroll()
    local Result = RNG:NextInteger(1, 1000)
    Iteration += 1

    if (Result < 750) then
        return "Basic"
    else
        return "Uncommon"
    end

    -- Logic can be implemented here to give rewards based off certain numbers or ranges being hit with the Result
end

Reroll()

Now with the way that Random works, it’s IDENTICAL to the way Minecraft seeds or anything similar to that works. That means if you were to use Random 10 times in a row, you will ALWAYS receive the same results in a row. But this can be randomized by using different seeds within the Random parameters.

So the idea is to save how many times into that Random we go, so that when we’re happy with our result the server can do it all as one transaction.

So when the player rolls whatever they’d like we’d fire that iterated number to the server, and it’d complete a full transaction:

local function CompleteTransaction(Player, IteratedInto)
    -- Obtain the data somehow... In this example we'll just have it

    local RNG = Random.new(ModifierRandomization)
    local RolledItem = nil

    for Index = 1, IteratedInto do
        local Result = RNG:NextInteger(1, 1000)

        if (Result and Index == IteratedInto) then
            -- Logic can be implemented here to give rewards based off certain numbers or ranges being hit with the Result
            -- MAKE SURE THAT IT'S IDENTICAL TO THE CLIENT RNG LOGIC

            if (Result < 750) then
                RolledItem = "Basic"
            else
                RolledItem = "Uncommon"
            end
        end
    end

    print(Player, "rolled ".. (RolledItem or "nothing...?")

    -- Remove coins based off of IteratedInto, or any other sort of logic you'd like! :D
end