Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there any way I can make this script less laggy, (FE btw)?

Asked by 6 years ago
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)
0
What about the script is lagging? Please provide some specifics instead of shoving code in our face and saying "Help its slow" Trewier 146 — 6y
0
you are using Ray casting, that is why.... greatneil80 2647 — 6y
2
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. XAXA 1569 — 6y
0
in other words, don't put an on server event inside another onserverevent (line 03, line 04) abnotaddable 920 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

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.

0
Finally, someone who agrees with me. Everyone gets mad at me when i say to read my bio. hiimgoodpack 2009 — 6y
1
It has a major issue that you overlooked. Please take a look at how OnServerEvent is nested inside another OnServerEvent. XAXA 1569 — 6y
0
Ah yes, thank you! I forgot you could use a remote event to also carry a location of a variable. Stephenthefox 94 — 6y
0
@XAXA I just looked over the OnServerEvent, I recommended to instead use only one event for the function. User#18043 95 — 6y
Ad

Answer this question