Help with FireAllClients

Hi, this is part of a remote event, how can i make the circled code run on every player’s client instead of the server because it gets pretty laggy?

I know i have to use FireAllClients but i don’t know how. I don’t understand what is supposed to be in the server script and what in the local script

C1kiMEc - Imgur

if v.OrePart.Values.HP.Value < 1 then


								--FROM HERE
								for i, v in pairs(v.OrePart.OreCubes:GetChildren()) do
									v.Anchored = false
									v.Parent = char
									v.CanCollide = false

									local RP = Instance.new("RocketPropulsion", v)
									RP.Target = char.UpperTorso
									RP.MaxSpeed = 100
									RP.ReachedTarget:Connect(function()
										v:Destroy()
									end)
									RP:Fire()
								end
								-----TO HERE


								for i, v in pairs(v.OrePart.OreStones:GetChildren()) do
									v.Position = v.Position + Vector3.new(0,-1000, 0)
								end
								v.OrePart.Position = v.OrePart.Position + Vector3.new(0,-1000,0)
								Debris:AddItem(v.OrePart.Parent, 5)
								game.ServerStorage.TotalOres.Value -= 1
							end

You should read the API reference.

Thank you, i did. As i said in the post, i don’t understand, this is why i came to the Dev Forum

In the server script you would do

local event = -- Path to event
event:FireAllClients(args)

Local script:

local event = -- Path to event
event.OnClientEvent:Connect(function(args)
   -- Code here

end)

Thanks but:

  1. What arguments am i supposed to put for FireAllClients() for the code to work in the local script?
  2. Can event:FireAllClients be called from another RemoteEvent?

Im thinking about doing this

Inside server script with the main remote event
event:FireAllClients(v)

Inside the local script

event.OnClientEvent:Connect(function(v)
local player = game.Players.LocalPlayer.Name
local char = game.Workspace[player]
for i, v in pairs(v.OrePart.OreCubes:GetChildren()) do
v.Anchored = false
v.Parent = char
v.CanCollide = false

local RP = Instance.new(“RocketPropulsion”, v)
RP.Target = char.UpperTorso
RP.MaxSpeed = 100
RP.ReachedTarget:Connect(function()
v:Destroy()
end)
RP:Fire()
end
end

Is this how im supposed to use it? Did i do it correctly?

Imagine each remote event as a separate utility line. Each one leads to your house.
We have electricity.
Phone line,
and Water line.
The server script is the main utility plant which controls everything, and the local script is your house.
FireAllClients uses that remote event, let’s say we’re using electricity, and we’re sending it to ALL the houses, we can send any variable/command with it also. We do not need to specify the house (player) to send it to.
so
MyRemoteEvent:FireAllClients(true,false,nil) Whatever I want to send.
FireClient is to a specific house, so we need to specify the specific house (player) to send it to.
MyRemoteEvent:FireClient(Plr, “Whatever variables I can send”, true, false)

1 Like

I think i did it but i have encountered another problem
Problem with Rocket Propulsion on Client Side - Help and Feedback / Scripting Support - DevForum | Roblox