I’m trying to create a SciFi blaster system in Roblox using Lua. The way I decided to go about this is using a raycast to apply the damage and a glowing bullet projectile with no collision to show the path of the bullet. This seemed like a good idea because the projectiles are lasers so they don’t need to have gravity.
The problem is that the bullets lag and then teleport through the air to catch up. This only happens in the published game, not in studio, which means (I think) that the problem has to do with the connection between the Client and Server, because Studio uses a Local Server setup. You can see the lagging here.
I thought I’d messed something up with one of the scripts I created, so I tried using the FastCast system to get an idea of its performance. However, the FastCast bullets lagged as well, leading me to believe that the problem may be somewhere else. I tried the weapons in an empty map, but the problems persisted. I also tried connecting the bullets movement to both the Heartbeat and the Stepped options.
Here is the script inside the bullet:
local RunService = game:GetService("RunService")
local blast = script.Parent
local studsPerSecond = blast:GetAttribute("Speed")
local timeElapsed = 0
local function MoveBullet(deltaTime)
local speed = -1 * studsPerSecond * deltaTime
blast.CFrame = blast.CFrame * CFrame.new(0,0,speed)
timeElapsed += deltaTime
if timeElapsed > blast:GetAttribute("Lifetime") then
Thank you for any help you can offer and please let me know if I need to add anything to the post for greater clarity.
This is definitely a issue with creating the visuals server-side. I recommend you to instead handle hit-detections on the server, and the visuals on clients side exclusively. FastCast has not been the issue, it’s just that you need to handle it on the client.
It is pretty easy, it should work like this:
A player fires ;
The client fires a remote to the server to handle the hitbox, and the player’s client handles the visuals for that client ;
Once the server gets the remote, you do a for loop, loop through all players, check if the player you are looping through is NOT the player who sent the remote (the player who sent the remote is the first argument being sent through) ;
Then, fire a remote from the server to that player’s client.
Back on the client, each client will handle the visuals once it receives that remote. The remote from the server to the client should provided all the info like projectile type and where its trajectory, etc. Make sure it only is handling visuals, all hitboxes and damage dealing should be handled on the server.