Help with remote events firing

Okay, so I’m trying to make a system in which you press a button and a random remote event is fired. I already made the table of remote events in Replicated Storage, but they won’t fire for some reason.
Here is an example of the script explained with outdated memes:
(Why in the world did I use these as an example out of everything…)
Script 1 (Location: Normal script within the button)

local button = game.Workspace.Button.Button

local player = game:GetService("Players").LocalPlayer

local RS = game:GetService("ReplicatedStorage")
local Events = RS.RandomEvents:GetChildren()

local IfButtonBusy = game.Workspace.Button.Button.IfButtonIsBusy
IfButtonBusy.Value = false

local function RandomEvent(player)
	if IfButtonBusy.Value == false then
		
		button.BrickColor = BrickColor.new("Really red")
		
		print("FUNCTION START!!")
		IfButtonBusy.Value = true

		local Random = math.random(1, #Events)
		local RandomEvent = Events[Random]
	
		RandomEvent:FireClient(player) --Error message
		
		print(RandomEvent.Name.. " was fired.")

		wait(10)
		IfButtonBusy.Value = false
		print("BUTTON RECHARGED!")
		button.BrickColor = BrickColor.new("Lime green")
	end
end

button.ClickDetector.MouseClick:Connect(RandomEvent)

Script 2 (Location: ServerScriptService) (Don’t really know if I need the player variable but I have it just because)

local player = game:GetService("Players").LocalPlayer

--Folder Variables
local RandomEvents = game.ReplicatedStorage.RandomEvents

--Event Variables
local Event1 = RandomEvents:WaitForChild("Creeper")
local Event2 = RandomEvents:WaitForChild("WidePres")
local Event3 = RandomEvents:WaitForChild("Yankee")

--Creeper function
local function CreeperAwMan()
	print("Creeper? Awww man.")
end


--Wide President function
local function WidePresident()
	print("lol is this meme dead?")
end


--Yankee w/ no brim function
local function YankeeBrim()
	print("YANKEE WITH NO BRIM!!")
end


--Event Connecting
Event1.OnServerEvent:Connect(CreeperAwMan)
Event2.OnServerEvent:Connect(WidePresident)
Event3.OnServerEvent:Connect(YankeeBrim)

Thank you in advance! :smiley:

2 Likes

You’re trying to fire a function

1 Like

Is the first script a ServerScript or a LocalScript?

It’s a normal script within the button. I tried using a local script before and it didn’t work for some reason.

Delete the Local player = game:GetService(“Players”).LocalPlayer cause that can be only used in a local script

1 Like

Okay I deleted the player variable and its still doing the same thing.
So, to give more insight, the entire function runs, and it prints the functions from the first script. But for some reason the second script’s print statements don’t print, and no errors show up so I have no idea how to fix it. I already tried getting rid of the player between parenthesis (Brought up an error, so I put it back) and switching the client and server parts of the script. (Also brought up an error; not sure why I thought it would work)

Is the second script a LocalScript cause if it is then it shouldn’t be in ServerScriptService

The second script is also a normal script

Put the Second Script code all in a Local Script and Change:
Event1.OnServerEvent:Connect(CreeperAwMan)
Event2.OnServerEvent:Connect(WidePresident)
Event3.OnServerEvent:Connect(YankeeBrim)
To:
Event1.OnClientEvent:Connect(CreeperAwMan)
Event2.OnClientEvent:Connect(WidePresident)
Event3.OnClientEvent:Connect(YankeeBrim)

You’re doing this.

RemoteEvent:FireClient()

You should receive it with
RemoteEvent.OnClientEvent:Connect(function()

But you’re doing RemoteEvent.OnServerEvent:Connect(function()

This should fix it

A remote event can only fire from server to client or vice versa.
You are firing from server to server right now,

1 Like

Also,
:FireClient() Only works in Scripts.

.OnClientEvent() Only works in Local scripts.

Yes, that’s true. I agree with you.

You could try to print the result of math.random().

It prints the result of math.random after the event is fired (It prints the variable name) but it doesn’t actually fire the event.

Anyways you’re doing :FireClient(), you should do :FireServer() from LocalScript.

Or you could do.

Script: FireClient()

LocalScript: .OnClientEvent() and :FireServer()

2nd Script: .OnServerEvent()

Not really sure why, but whenever I make it a Local Script in the button, the entire script doesn’t run.
Also, I changed that one line of Script 1 to

RandomEvent:FireServer()

and the last few lines of Script 2 to

ExampleEvent.OnServerEvent:Connect(ExampleFunction)

And whenever I change either script to a local script it just dies XD

Before you start with this, make sure to learn it!

Article: Custom Events and Callbacks | Documentation - Roblox Creator Hub

Script 1, the one inside of the button should be the server script.

The second script, which you can put in StarterPlayerScripts should be a local script.

In script 1 you should use RandomEvent:FireClient(player)
in script 2, the local script, you should use RandomEvent.OnClientEvent:Connect(ExampleFunction)