local Event1 = game.ReplicatedStorage.Events.RemoteEvent
Event1.OnServerEvent:connect(function(Player,FireRay)
FireRay.OnServerEvent:connect(function(Player,Tool,ray,part,position,distance,RateOfFire)
local Chr = game.Workspace:FindFirstChild(Player.Name)
local beam = game.ReplicatedStorage.Events.Beam:Clone()
beam.Parent = workspace.RayHolder
beam.Mesh.Scale = Vector3.new(0.1, 0.1, distance)
beam.CFrame = CFrame.new(Tool.FrontBarrel.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
wait(.01)
game.Debris:AddItem(beam, 0.03)
end)
end)
Is there any way I can make this script less laggy, (FE btw)?
1 answer
I don't think anything is wrong with your script besides the fact that you require a remote event to be fired in order to receive a signal from another remote event called FireRay when you could instead just receive the signal from that remote event.
You can improve the script by using :Connect() because :connect() is deprecated. You could also improve code by using less code with the usage of workspace instead of game.Workspace.
You can also indent your code and make it look organized.
My answer focuses on how to make your code look cleaner rather than making it less laggy because it doesn't look like it has lag issues.
4 comments
Finally, someone who agrees with me. Everyone gets mad at me when i say to read my bio.
It has a major issue that you overlooked. Please take a look at how OnServerEvent is nested inside another OnServerEvent.
Ah yes, thank you! I forgot you could use a remote event to also carry a location of a variable.
@XAXA I just looked over the OnServerEvent, I recommended to instead use only one event for the function.
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
What about the script is lagging? Please provide some specifics instead of shoving code in our face and saying "Help its slow"
you are using Ray casting, that is why....
Raycasting isn't laggy. Although, I find it... interesting that you're nesting an OnServerEvent callback INSIDE another OnServerEvent callback. With your current script, a new connection to FireRay is being created EVERY TIME Event1 fires. This is probably unintended.
in other words, don't put an on server event inside another onserverevent (line 03, line 04)