How Would I Go About Making Random Encounters?

Hi, I’m currently trying to make a system where if you walk in a certain area for a bit, there will be things you can randomly encounter. I have no idea how to do this.

Now if you don’t understand my explanation above, think about pokemon. Pokemon has random encounters that work just like this.

I also want to know how to make only a certain amount of creatures encounterable in one patch of grass/area.

Example code would be highly appreciated.

Every frame you can do a random number like 1 in 10000. If this is equal to 1 and you are in the right area then do a random event. Also make sure that there is no other random event already going on.

You could maybe implemented a Touched event & a debounce every time the Character touches the Grass Areas, or Region3 either one would work

Depending on what grass it is, maybe you could do something along the lines like this for separating the Pokemon?

local Part = script.Parent
local DB = false
local PokemonToCounter = {
    ["BootlegChance"] = 50;
    ["BootlegChance2"] = 10;
    ["BootlegChance3"] = 1;
}

local ChanceSystem = 0
for _, Chance in pairs(PokemonToCounter) do
    ChanceSystem += Chance
end

Part.Touched:Connect(function(Hit)
    if not DB then
        DB = true
        local EncounterChance = math.random(1, ChanceSystem) 
        if EncounterChance == 1 then
            --Do the encounter thing here
        end
    task.wait(0.5)
    DB = false
    end
end)

This is just a broad example, you could implement something along the lines of this I suppose

1 Like

This actually seems very nice. I definetly will use this initially

1 Like

Your script gives me this error?

attempt to perform arithmetic (add) on number and nil

Do you know how to fix this?

No clue why you’re responding back to this after 2 years

Keep in mind that I gave a broad example back then, so not everything’s exactly perfect as you’ll have to figure out the rest on your own

I went ahead and re-did the script however, so it should work now

How do you make it so that it only gives you an encounter after a random amount of time (between like 3 to 7 seconds) and you have to be walking and touching the grass. If you stop walking or leave the grass it resets the timer