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
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.
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.