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

Why won't RemoteEvent FireAllClients work?

Asked by
Dad_Bot 34
7 years ago

I am making a painting game where players can change pixel colors on a SurfaceGui in order to paint a Canvas. This process is all local. Then, the player clicks a done button and the canvas, which was local, is supposed to duplicate somewhere where everyone can see it. I have this localscript, when the button is pressed. This RemoteEvent works as it is supposed to.

LocalScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local duplicate = ReplicatedStorage:WaitForChild("duplicate")
local pasteEvent = ReplicatedStorage:WaitForChild("paste")

script.Parent.MouseButton1Click:connect(function()
duplicate:FireServer()
end)

The duplicate Remote Event ServerScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local duplicate = ReplicatedStorage:WaitForChild("duplicate")
local PaintingLandscape = workspace.PaintingLandscape
local pasteEvent = game.ReplicatedStorage.paste

local function onClone(player)
    local clonepainting = PaintingLandscape:Clone()
    clonepainting.Name = "Canvas"
    clonepainting.Position = Vector3.new(-13.99, 5, 0.431)
    clonepainting.Parent = game.Workspace
    local cloneGUI = player.PlayerGui.Studio.Canvas:Clone()
    cloneGUI.Name = "Painting"
    cloneGUI.Parent = game.ReplicatedStorage
    cloneGUI.Adornee = clonepainting
    pasteEvent:FireAllClients()

end

duplicate.OnServerEvent:connect(onClone)

Once again, this works fine. However, the pasteEvent:FireAllClients() line does not fire. This is the local script that is supposed to fire for all clients:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local pasteEvent = ReplicatedStorage:WaitForChild("paste")
local painting = game.ReplicatedStorage.Painting

local function onPaste()
    wait(1)
    local clone = painting:Clone()
    clone.Parent = player.PlayerGui
    clone.Adornee = workspace.Canvas
end

pasteEvent.OnClientEvent:Connect(onPaste)

If anyone could figure out this problem, or at least make an attempt, I would really appreciate it! :)

0
@RockerCaleb1234 I always struggle to use them because I don't understand how they work. I've read the wiki but it is complicated for me. Would it be easy to convert this to a Remote Function? Dad_Bot 34 — 7y
0
A simple solution for this would be to make a second remote that the server uses to connect to your 2nd local script. Idk if this is the best way though. RockerCaleb1234 282 — 7y
0
@RockerCaleb1234 Why doesn't this script work in the first place? Dad_Bot 34 — 7y

2 answers

Log in to vote
0
Answered by
Dad_Bot 34
7 years ago

Okay I figured it out to anyone having the same issues. I needed to put the last localscript in StarterPlayerScripts.

Ad
Log in to vote
0
Answered by 7 years ago

You cannot have a client use :FireAllClients(), probably because of security issues. Instead, fire a remote event to the server to fire :FireAllClients().

Answer this question