Their are two problems actually one: My bullet isn't facing straight when I shoot it for some reason and two my bullet will stop for a second then move. I'm not sure why but
LocalScript
function createbullet() local flash = cam[currentgun.Name][currentgun.Name].Flash.CFrame rep.Events.Bullet:FireServer(mouse.hit, flash, p) end
ServerScript
game.ReplicatedStorage.Events.Bullet.OnServerEvent:connect(function(player, mousehit, flash, p) local bullet = game.ReplicatedStorage.Bullet:Clone() bullet.CFrame = CFrame.new(flash.p) local bv = Instance.new("BodyVelocity", bullet) bv.MaxForce = Vector3.new(1e8, 1e8, 1e8) bv.Velocity = mousehit.lookVector * 500 bullet.CanCollide = false bullet.Parent = workspace game.Debris:AddItem(bullet, 2)
Any help will be appreciated
This problem is most likely caused by the latency between the server and client when the network ownership of the bullet switches from the client to the server (you shouldn't have this problem if accurate play solo is disabled).
The solution is to call SetNetworkOwner()
on the bullet with an argument of nil
(this means that the physics will be calculated on the server) like so:
--Server Script game.ReplicatedStorage.Events.Bullet.OnServerEvent:Connect(function(player, mousehit, flash, p) local bullet = game.ReplicatedStorage.Bullet:Clone() bullet.CFrame = CFrame.new(flash.p) local bv = Instance.new("BodyVelocity", bullet) bv.MaxForce = Vector3.new(1e8, 1e8, 1e8) bv.Velocity = mousehit.lookVector * 500 bullet.CanCollide = false bullet.Parent = workspace bullet:SetNetworkOwner(nil) game.Debris:AddItem(bullet, 2) end)
you can get around this issue by not using a body velocity. Instead of a body velocity, you can use the velocity property of base parts.
For example:
local bullet = game.ReplicatedStorage.Bullet:Clone() bullet.CFrame = flash --assuming flash is a CFrame here bullet.Velocity = mousehit.lookVector * 500
Now for the future, try not to use the parent argument of Instance.new as it causes some performance issues. Also try to steer away from CFrame.p and connect in favor of CFrame.Position and Connect.