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)
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.