Help with client effects to server

hello i am pretty new to remote events/functions and i am using Quasiducks lightning beams and I made it so the lightning bolt plays when you click a button it fires a remote event making a lightning bolt in the server and then playing it to all clients. It works but it has a delay since its running of the server.

Is there any way to make it hide the delay by running on client and sending it to the server so its only delayed for others but not you?

Local script:

local event = game.ReplicatedStorage.RemoteEvent
local remoteFunction = game.ReplicatedStorage.RemoteFunctionTest

local LightningBolt = require(game.Workspace.Model.LightningBolt)
local LightningSparks = require(game.Workspace.Model.LightningBolt.LightningSparks)
local LightningExplosion = require(game.Workspace.Model.LightningBolt.LightningExplosion)

local button = game.Workspace.button
local click = button.ClickDetector


function onClick()
	event:FireServer()
end

event.OnClientEvent:Connect(function()
	local NewBolt2 = LightningBolt.new(workspace.Model.Part4.Attachment4, workspace.Model.Part3.Attachment3, 20)
	NewBolt2.CurveSize0 = math.random(-20,20)
	NewBolt2.CurveSize1 = math.random(-20,20)
	NewBolt2.PulseSpeed = 15
	NewBolt2.PulseLength = 5
	NewBolt2.FadeLength = 0.3
	NewBolt2.MaxRadius = 2
	NewBolt2.Frequency = 1
	NewBolt2.Color = Color3.new(0.854902, 0.701961, 0.188235)
	local newSparks = LightningSparks.new(NewBolt2, 40)
	newSparks.LightningBolt = NewBolt2
	local newExplosion = LightningExplosion.new(workspace.Model.Part3.Position, 1, 5, Color3.new(0.854902, 0.701961, 0.188235), Color3.new(0.854902, 0.701961, 0.188235))	
end)

click.MouseClick:Connect(onClick)

Server:

local event = game.ReplicatedStorage.RemoteEvent
local remoteFunction = game.ReplicatedStorage.RemoteFunctionTest

local LightningBolt = require(game.Workspace.Model.LightningBolt)
local LightningSparks = require(game.Workspace.Model.LightningBolt.LightningSparks)
local LightningExplosion = require(game.Workspace.Model.LightningBolt.LightningExplosion)

event.OnServerEvent:Connect(function(player)
	local NewBolt2 = LightningBolt.new(workspace.Model.Part4.Attachment4, workspace.Model.Part3.Attachment3, 20)
	NewBolt2.CurveSize0 = math.random(-20,20)
	NewBolt2.CurveSize1 = math.random(-20,20)
	NewBolt2.PulseSpeed = 15
	NewBolt2.PulseLength = 5
	NewBolt2.FadeLength = 0.3
	NewBolt2.MaxRadius = 2
	NewBolt2.Frequency = 1
	NewBolt2.Color = Color3.new(0.854902, 0.701961, 0.188235)
	local newSparks = LightningSparks.new(NewBolt2, 40)
	newSparks.LightningBolt = NewBolt2
	local newExplosion = LightningExplosion.new(workspace.Model.Part3.Position, 1, 5, Color3.new(0.854902, 0.701961, 0.188235), Color3.new(0.854902, 0.701961, 0.188235))
	event:FireAllClients(player)	
end)

i dont really get what you mean, could you explain in more detail?

Your code can be easily modified to play instantly for the player who clicked the button.

In the local script, turn this section:

function onClick()
	event:FireServer()
end

event.OnClientEvent:Connect(function()
	local NewBolt2 = LightningBolt.new(workspace.Model.Part4.Attachment4, workspace.Model.Part3.Attachment3, 20)
	NewBolt2.CurveSize0 = math.random(-20,20)
	NewBolt2.CurveSize1 = math.random(-20,20)
	NewBolt2.PulseSpeed = 15
	NewBolt2.PulseLength = 5
	NewBolt2.FadeLength = 0.3
	NewBolt2.MaxRadius = 2
	NewBolt2.Frequency = 1
	NewBolt2.Color = Color3.new(0.854902, 0.701961, 0.188235)
	local newSparks = LightningSparks.new(NewBolt2, 40)
	newSparks.LightningBolt = NewBolt2
	local newExplosion = LightningExplosion.new(workspace.Model.Part3.Position, 1, 5, Color3.new(0.854902, 0.701961, 0.188235), Color3.new(0.854902, 0.701961, 0.188235))	
end)

into:

function onClick()
	event:FireServer()
	-- EDIT: show the effect instantly instead of waiting for the server to fire back the remote event)
	createLightning()
end

-- EDIT: no longer an anonymous function
function createLightning()
	local NewBolt2 = LightningBolt.new(workspace.Model.Part4.Attachment4, workspace.Model.Part3.Attachment3, 20)
	NewBolt2.CurveSize0 = math.random(-20,20)
	NewBolt2.CurveSize1 = math.random(-20,20)
	NewBolt2.PulseSpeed = 15
	NewBolt2.PulseLength = 5
	NewBolt2.FadeLength = 0.3
	NewBolt2.MaxRadius = 2
	NewBolt2.Frequency = 1
	NewBolt2.Color = Color3.new(0.854902, 0.701961, 0.188235)
	local newSparks = LightningSparks.new(NewBolt2, 40)
	newSparks.LightningBolt = NewBolt2
	local newExplosion = LightningExplosion.new(workspace.Model.Part3.Position, 1, 5, Color3.new(0.854902, 0.701961, 0.188235), Color3.new(0.854902, 0.701961, 0.188235))	
end

-- EDIT: nothing changed, it's connected to the same function as before
event.OnClientEvent:Connect(createLightning)

On the server side script, you should not create the lightning bolt. Instead, fire the remote event to all players except for the one who pressed the button, because he has already seen it locally.
If you use FireAllClients to send the event to all players including the presser, then the presser will see two lightning bolts, but everyone else will see only one.

thanks for the reply it works great!

however im a bit confused, is there a specific way to rule out the player who clicked the button from FireAllClients?

There are two ways:

  1. Supply the player who fired the event to FireAllClients. In the OnClientEvent connection, if the player who fired is the current player, then ignore/return.

  2. Don’t use FireAllClients, instead loop over all players and fire to all except the player who clicked the button