Is this method efficient or are there better ways to do this

Hello,

I’ve created an advanced gunsystem with all kinds of visual effects. I’ve thought about two options to handle these effects: either running them on the server or sending them to all clients.

  • A client shoots a weapon, firing a RemoteEvent.
  • Server takes remoteEvent and data.
  • Server fires some data to all clients (position of where bullet has hit for example)
  • All clients take data, calculates effects then renders them on their screens, seeing another player fire their weapon.

The issue is that I have calculations for the effects, one of them being tracers.

These tracers have to be calculated/animated and that would be a lot of workload on the server. I can move it to all clients but the server will have to run a FireAllClients() everytime a player fires a weapon (a lot of players and a quick firerate means many remoteEvents fired)

Is this efficient?
(I never create topics, apologies if it isn’t formatted correctly or hard to understand)

2 Likes

Handling Visual Effects in a Roblox Gun System

When creating an advanced gun system with visual effects in Roblox, there are a few options to consider for handling these effects. One option is to run the effects on the server, while another is to send them to all clients.

Server-Side Effects

If you choose to run the effects on the server, you can use a RemoteEvent to fire data from the client to the server when a player shoots a weapon. The server can then take this data and perform calculations for the visual effects, such as tracers.

Here’s an example of how this might look in code:

-- Client-side script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shootEvent = ReplicatedStorage:WaitForChild("ShootEvent")

local function onShoot()
    -- Get data about the shot (e.g., position of bullet hit)
    local data = ...
    shootEvent:FireServer(data)
end

-- Server-side script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shootEvent = ReplicatedStorage:WaitForChild("ShootEvent")

local function onShoot(data)
    -- Calculate visual effects using data
    local tracers = ...
end

shootEvent.OnServerEvent:Connect(onShoot)

One potential issue with running visual effects on the server is that it can increase the workload on the server. If you have many players and a high fire rate, this could affect performance.

Client-Side Effects

Another option is to send visual effect data from the server to all clients using FireAllClients() . This allows each client to perform calculations and render visual effects locally.

Here’s an example of how this might look in code:

-- Server-side script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shootEvent = ReplicatedStorage:WaitForChild("ShootEvent")

local function onShoot(player, data)
    -- Send data about shot (e.g., position of bullet hit) to all clients
    shootEvent:FireAllClients(data)
end

shootEvent.OnServerEvent:Connect(onShoot)

-- Client-side script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shootEvent = ReplicatedStorage:WaitForChild("ShootEvent")

local function onShoot(data)
    -- Calculate and render visual effects using data
    local tracers = ...
end

shootEvent.OnClientEvent:Connect(onShoot)

While running visual effects on the client-side can reduce workload on the server, it’s important to consider network traffic. If you have many players and a high fire rate, sending many remote events could result in increased network traffic and potentially affect performance.

Conclusion

In conclusion, there are trade-offs between running visual effects on the server versus sending them to all clients. It might be helpful to test both options and see which one works best for your specific use case. You may also want to consider optimizing your code and reducing network traffic where possible.

3 Likes

Ah alright I should probably not worry about the network being overloaded then. Thanks mate

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.