Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

Why isn't this remote event, which communicates from server to client, working properly?

Asked by 5 years ago

I have a remote event going from a server to a client. It doesn't seem to work as I don't receive any output from the print function on the local script.

This is the server script.

ReplicatedStorage = game.ReplicatedStorage
dialogEvent = ReplicatedStorage.dialogEvent

dialogEvent:FireAllClients()

This is the local script.

ReplicatedStorage = game.ReplicatedStorage
dialogEvent = ReplicatedStorage.dialogEvent

function onDialogEventFired()
    print("finally")
end

dialogEvent.OnClientEvent:Connect(onDialogEventFired)
0
You may have to do ReplicatedStorage:WaitForChild("dialogEvent") User#21908 42 — 5y

1 answer

Log in to vote
3
Answered by 5 years ago
Edited 5 years ago

Likely isn't working because not everything in the game hasn't loaded in yet. I added GetService on ReplicatedStorage, and a WaitForChild for the event itself just to make sure they loaded in, also added a wait() right before firing the event and it worked.

Server Code:

ReplicatedStorage = game:GetService("ReplicatedStorage")
dialogEvent = ReplicatedStorage:WaitForChild("dialogEvent")
wait()
dialogEvent:FireAllClients()

Client Code:

ReplicatedStorage = game:GetService("ReplicatedStorage")
dialogEvent = ReplicatedStorage:WaitForChild("dialogEvent")

function onDialogEventFired()
    print("finally")
end

dialogEvent.OnClientEvent:Connect(onDialogEventFired)

The things I added shouldn't delay the code enough to mess anything important up.

0
Brill! Thank you, really appreciate the response! TruDevek 40 — 5y
Ad

Answer this question