OnServerEvent and FireAllClient not communicating

Hi there!

For some reason, my script that is placed in a MouseDetector is not firing whenever triggered.
I am trying to fire an event whenever a part is clicked, this will in return will be received by another part.

ClickDetector Script:

local click = script.Parent
local gatesound = game:GetService("SoundService"):WaitForChild("angel fire sound")
click.MouseClick:Connect(function(player)
	local gate = game.Workspace:FindFirstChild("Gate")
	gate.Transparency = 0
	gatesound:Play()
	gate.ParticleEmitter.Enabled = true
	
	local HCE = game:GetService("ReplicatedStorage").HolyCubeEvent
	HCE:FireClient(player)
	
	wait()
	click:Destroy()
end)

Part Script:

local HCE = game:GetService("ReplicatedStorage").HolyCubeEvent
local debounce = false

HCE.OnServerEvent:Connect(function(player)
debounce = true
	print("hello")
	
end)

The debounce = true is needed for triggering a function in the part script.

for Server to Client event communication. You need to use :FireClient() or :FireAllClient() and Event.OnClientEvent. not Event.OnServerEvent.
for Server to Server communication. use BindableEvent instead. Same for Client to Client communication

Hey!

Is the Mouse detector on the Server, or Client?

Ideally with this setup you’ll want a ClickDetector and its script on the Server which then uses FireClient to contact the Client, if there’s a requirement for that.

This code can be fixed if the “Part script” exists on the Client and you change OnServerEvent to OnClientEvent, as that’s what the Click detector is firing.

You need to change OnServerEvent to OnClientEvent for it to be fired from the ClickDetector script. Also, make sure your PartScript is a local script.

1 Like

MouseDetector script is a server thing, I am trying to get it to communicate with another part using server scripts.

The ClickDetector and its script are both server sided. I am trying to get it to communicate with anther part using .OnServerEvent in the part.

In this instance, as @idkhowtousername said, just use Bindable events rather than a remote event. Remote events are only used when you want the Client to contact the Server, or the Server to contact the Client.

For Server → Server communication, or Client → Client, use Bindable events.

Bindable events documentation. - ROBLOX .
How do Bindable events work? - DevForum