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

Why doesn't FireAllClients work when trying to send?

Asked by 4 years ago

Code: server:

script.Parent.Triggered:Connect(function(player)
    game.ReplicatedStorage.Open:FireAllClients()
    print("A")
end)

Client:

game.ReplicatedStorage.Open.OnClientEvent:Connect(function()
    print("B")
    openDoor()
end)

Output: A (no B)

0
Is the client script located in a place where local scripts can run? User#32819 0 — 4y
0
your remote event is fine. `Triggered` is not a valid event. I assume you meant `script.Parent.Touched` Gey4Jesus69 2705 — 4y

2 answers

Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

FireAllClients Command

When it comes to using the :FireAllClients() feature... I would only use that when you're trying to call to a LocalScript inside of StarterGui/StarterPlayerScripts/StarterCharacterScripts. That's my recommendation but use it as you believe fits. Here's a link that will lead you to how the FireAllClients command works.

Your Error

The error in your script is the script.Parent.Triggered:Connect, after reviewing the script; I realized I missed this MASSIVE mistake. What you need to do is changed Triggered to Touched.

Server Script

script.Parent.Touched:Connect(function(player)
    game.ReplicatedStorage.Open:FireAllClients()
    print("A")
end)

Local Script

Do note that this command may not work if the LocalScript is in workspace, ReplicatedStorage, ReplicatedScriptService, ServerScriptService and ServerStorage.

game.ReplicatedStorage.Open.OnClientEvent:Connect(function()
    print("B")
    openDoor()
end)
0
no, just no... Gey4Jesus69 2705 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago

As explained in my comment above...

Server Script

script.Parent.Touched:Connect(function(player) --not Triggered
    game.ReplicatedStorage.Open:FireAllClients()
    print("A")
end)

Local Script

game.ReplicatedStorage.Open.OnClientEvent:Connect(function()
    print("B")
    openDoor() --im assuming you have this function defined somewhere
end)
0
FireAllClients() doesn't work unless the script that's collecting thats being called is on the client alone. I've tried using a local script in Workspace, ServerScriptService, ReplicatedStorage, ReplicatedScriptService and so on. It doesn't work that way; you should at the least advise the OP to only use `:FireAllClients()` for scripts/functions that are in local scripts for strictly that player. Just2Terrify 566 — 4y
0
Also, instead of saying `no, just no...`; you should give a proper reason why you give something a downvote. I know what I messed up on and i'm fixing the issue after this post. As a Community Moderator Voter; you should be use to this by now. No, i'm not trying to cause issues but telling you some flaws about your answer. Last thing; I'd remove your comments and move them into your answer. Just2Terrify 566 — 4y

Answer this question