Experiencing lag spikes while rendering bullets

After rigorous testing I am unable to determine how to fix the lag which appears each time the bullet gets rendered.
I am making use of 3 scripts,

  1. Tool Handler, client.
  2. Gun Handler, server.
  3. Bullet Renderer, client.

Whenever I fire a bullet, the tool handler sends an event to the bullet renderer and sends a remote event to the gun handler, the gun handler sends it to every single other player except the client which the request originated from.

After disabling the Bullet Renderer we have figured out that the lag which is shown on the video comes from the Bullet Renderer, specifically setting the parenting/cloning of the bullet. Please note that the Bullet Renderer is only responsible for the actual creating of the part, not the sound itself. I have also tested not setting any property except the parent, which shows no change in the lag. Reducing/increasing the graphics quality has also not changed the lag.

After also having made a bullet pooling system the lag experienced while rendering has not changed a single bit. Any help would be hugely appreciated. Testing on studio, team create and roblox has yielded the same result and the lag has not seemed different, I have had other developers test the game, but they also experienced lag.

Example of the complete gun system with the rendering:

Example of the gun system without setting the position, size & color.

The final test which I have done is not setting any properties of the template either, this has not had a big impact on the actual lag. You can see the drop in frames in both videos above.

Bullet renderer, parented under StarterPack (Player’s Backpack).

local bulletTemplate = Instance.new("Part")
--[[bulletTemplate.Name = "Ray" 
bulletTemplate.Anchored = true
bulletTemplate.CanCollide = false 
bulletTemplate.CanQuery = false
bulletTemplate.CanTouch = false
bulletTemplate.Size = Vector3.one*.15 
bulletTemplate.TopSurface = Enum.SurfaceType.Smooth
bulletTemplate.BottomSurface = Enum.SurfaceType.Smooth
bulletTemplate.BrickColor = BrickColor.new("Bright red") 
--bulletTemplate.Reflectance = 0
--bulletTemplate.Transparency = 0.25 
bulletTemplate.Material = Enum.Material.SmoothPlastic
bulletTemplate.Transparency = 0
]]
local localPlayer = game:GetService("Players").LocalPlayer
bulletParent = workspace:WaitForChild("BulletHolder")

function renderBullet(plr, startPos, endPos)
	print(plr, startPos, endPos)

	local bullet = bulletTemplate:clone()
	--bullet.Color = (plr.Team and plr.Team:FindFirstChild("BColour").Value) or (plr.TeamColor and plr.TeamColor.Color) or Color3.new(1,1,1)
	--bullet.CFrame = CFrame.new((startPos + endPos)/2, endPos)
	--bullet.Size = Vector3.new(.15, .15, (startPos-endPos).magnitude)
	bullet.Parent = bulletParent

	game:GetService("Debris"):AddItem(bullet, .06)

end

game:GetService("ReplicatedStorage"):WaitForChild("GunRemotes"):WaitForChild("BulletRemoteEvent").OnClientEvent:connect(function(plr, pos1, pos2)
	if plr == game.Players.LocalPlayer then return end -- this never gets run
	renderBullet(plr, pos1, pos2)

end)
script:WaitForChild("Event").Event:connect(function(pos1, pos2)
	-- this gets run
	renderBullet(localPlayer, pos1, pos2)
end)

If you would like to experience it for yourself, you can play this game any of the guns are laggy while rendering the bullets.

After testing the game without parenting the game experiences 0 lag. Debris service seems to not be the issue.

Another test with setting only the parent & surfaces:

Lag is heavily reduced, after setting every single property except the parent property.

Hey guys make sure that your fellow developers have not accidentally ungrouped a rig (with a humanoid) in it inside of workspace, because this creates huge amounts of lag.

3 Likes

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