How can I render bullets in the client side?

Hello There!

I’m creating a minigun and it works perfectly fine but for one small issue, as the title says, I want the bullets that fire out of the gun to be rendered in the client side. The reason why I wanted to render in the client side is because to prevent the bullets that spew out of the minigun to be heavily offset.

The script below this text is how the minigun currently fires its bullets.

local Tool = script.Parent
local FireEvent = Tool:WaitForChild("LaazerTime")
--//Functionality
FireEvent.OnServerEvent:Connect(function(Plr,MousePOS)
	local Bullet = Instance.new("Part",workspace.Debris)
	game:GetService("Debris"):AddItem(Bullet,5)
	Bullet.Size = Vector3.new(0.5, 0.5, 0.5)
	Bullet.CanCollide = false
	Bullet.CastShadow = false
	--Pos
	Bullet.Position = Tool.FirePart.Position
	Bullet.CFrame = CFrame.new(Tool.FirePart.Position,MousePOS)
	
	--Moving Bullet
	Bullet.Velocity = CFrame.new(Tool.FirePart.Position,MousePOS).LookVector * 1000
	local AntiGrav = Instance.new("BodyForce")
	AntiGrav.Force = Vector3.new(0, workspace.Gravity * Bullet:GetMass(), 0)
	AntiGrav.Parent = Bullet
	
	--Damaging
	local HasHit = false
	Bullet.Touched:Connect(function(OnHit)
		local Hum = OnHit.Parent:WaitForChild("Humanoid")
		if Hum and HasHit == false then
			HasHit = true
			
			Hum:TakeDamage(9)
			Bullet:Destroy()
		end
	end)
end)
1 Like

How about you create them on the server and the client at the same time but have the server actually do the logic like damage

I don’t really think that’s necessary, plus wouldn’t that actually make lag slightly powerful?

You said that you dont want the bullet to be offsetted by alot, if they are created on the client they’ll be where the client percieved them too be, at the same exact time you can create bullets on the server aswell that the player who fired the minigun wont be able too see but everyone else will be able too, so it looks responsive on their end, while the server is still handling logic like damage

Well, I guess I’ll try doing that.

1 Like

So, I guess I just make the bullet in the both in the client and server but do the logic in the server, correct?

Yeah but then when the bullet hits on the client youd send that it hit to the server which could open up some vulnerabilities, what you wanna do is make them on both the client and the server, but only check if its hit on the server; although on higher ping there might be a delay in the thing getting damaged the players firing the gun will steal see it happening in basically real time since your rendering the bullet on the client side; which if you think about it will make up for it in a sense

So basically player fires the gun, you create a client copy of the bullet first, right after that you send a remote to the server telling it to also create a bullet and then that bullet you have created on the server can go inside of a folder called bullets or something and then you can also rename the bullet to have like the players userid like bullet_(ID), and then on the client you can have a child added event in the bullets folder and check if the bullet has your user id inside of it and if it does make it invisible, this way you dont have double the bullets but other players will still be able too see the bullets your firing but its after the event has reached the server while youve already fired the bullet client sided and you;ve gotten immediate feedback for it

So basically, each time the gun is fired:
Two separate scripts creates a bullet to render the bullets both in the client side and server side and they both move where the mouse is at, although only the server-sided bullet will have the logic to damage players, is that correct?

By the way, here’s some clarification:

It is not possible to 100% fix exactly the lag bug where the client sees that the bullet hits the enemy but it didn’t kill it. The only way to go around that is to make the bullet on the server and not the client. Even if you did this though, players may think that they fired the gun but the bullets came out after a delay.

So, you’ll have to decide which one: Gun firing delay (bullet on the server) or seemingly hit but shot “didn’t” register (bullet on the client).

Well your going to want to do the same physics calculations on both the client and the server, to ensure they go to the same place;

Server does the logic to damage players. It’s also a little more difficult if you want to counter lag with using physics, since lag is always changing and almost impossible to predict (you can only get average ping).

If you’ve ever played rocket league it has probably one of the greatest lag compensation systems ive probably ever seen in a game

Source : GDC March 21-23 2018

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