Fire A Remote Event Randomly?

Hello today i have a rain system that activates on a timer, but i was wondering is there anyway i could fire a remote event randomly?. I know jailbreak has something like this but i doubt it involves remote events. The script the activates the remote event is in ServerScriptService and the script that sets the conditions and activates the rain and thunder is in StarterGui, but we will be focusing on the one in ServerScriptService.

Script

   local RS = game:GetService("ReplicatedStorage")
    local REs = RS:WaitForChild("REs")
    local rE = REs:WaitForChild("WeatherHandler")

    while true do
    	wait(960)

    	print("Starting Rain")
    	rE:FireAllClients("Start")
    	
    	
    	wait(300)
    	
    	print("Ending Rain")
    	rE:FireAllClients("Stop")
    end
2 Likes

Use Random

local newRandom = Random.new()
   local RS = game:GetService("ReplicatedStorage")
    local REs = RS:WaitForChild("REs")
    local rE = REs:WaitForChild("WeatherHandler")

    while true do
    	wait(newRandom:NextInteger(50,100))-- picks number between 50 and 100

    	print("Starting Rain")
    	rE:FireAllClients("Start")
    	
    	
    	wait(newRandom:NextInteger(20,40))-- random number between 20 and 40
    	
    	print("Ending Rain")
    	rE:FireAllClients("Stop")
    end

This was written on mobile and not tested, but it should work.

3 Likes

You can also just use Random as @xuefei123 stated. But instead of sending a random number, you can check if the number is above or below a thresh hold. Say if its Above 50 you can activate rain, if its below 50 you can deactivate rain. This way you get a 50/50 chance. This can be adjusted so you can get whatever percentage you want.

3 Likes

You can put the Remote Events’ name on a table and get a random one from there and then you can make the script find first child in the replicated storage

local Weathers = {
"Rain";
"Snow";
"Thunder"
}
local theChosenOne = math.random(1, #Wheaters)
game.ReplicatedStorage:FindFirstChild(Weathers[theChosenOne]):FireServer()

You can use it like this. Tell me if it doesn’t work.

4 Likes