Delayed bullet movement

This is a support category for asking questions about how to get something done on the Roblox websites or how to do something on Roblox applications such as Roblox Studio.

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A gun.

  2. What is the issue? Include screenshots / videos if possible!

movement delay with the bullet

local script:

local gun = script.Parent
local handle = gun.Handle
local gunBulletHole = gun.BulletHole
local remote = gun.RemoteEvent

local rs = game:GetService("ReplicatedStorage")
local bullets = rs:WaitForChild("Bullets")
local bulletHole = bullets:WaitForChild("BulletHole")
local pistolBullet = bullets:WaitForChild("Pistol")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
	remote:FireServer(mouse.Hit.Position)
	print("Shot")
end)

server script:

local rs = game:GetService("ReplicatedStorage")
local bullets = rs.Bullets
local pistolBullet = bullets.Pistol

local gun = script.Parent
local remote = gun.RemoteEvent

remote.OnServerEvent:Connect(function(player, mousePos)
	local bullet = pistolBullet:Clone()
	bullet.Parent = workspace
	bullet.CFrame = CFrame.new(gun.BulletHole.Position, mousePos)
	
	local attachment = Instance.new("Attachment", bullet)
	
	local lv = Instance.new("LinearVelocity", attachment)
	lv.MaxForce = math.huge
	lv.VectorVelocity = bullet.CFrame.LookVector * 100
	lv.Attachment0 = attachment
	
	game.Debris:AddItem(bullet, 3)
end)
  1. What solutions have you tried so far? Did you look for solutions on the Creator Hub?

I have tried using body velocity instead.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

1 Like

Since you’re creating an actual physical part and applying forces to it on the server side, there will always be a delay as it takes time for the server to receive the event from the client and then have the server simulate the physics on that part. It also takes a little more time for the server to replicate those physics changes back to your client.

To help with this, you could go with a raycast that is split up into small segments. When you split up the raycast you can apply physical forces to the raycast at each update.

If you don’t want to make it yourself there’s a public module, FastCast that does exactly that. I think there’s a few other options out there as well but you’d have to go looking for them; FastCast is the most popular afaik. Fair warning though, it is prone to performance and hitreg issues though so keep that in mind.

Hope this helped! :slight_smile:

1 Like

thanks I found out if I set the network owner of the part to the player it works

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