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! :)
Okay I figured it out to anyone having the same issues. I needed to put the last localscript in StarterPlayerScripts.
You cannot have a client use :FireAllClients()
, probably because of security issues. Instead, fire a remote event to the server to fire :FireAllClients()
.