The projectiles don’t spawn where there supposed to spawn while the character is moving/running, the projectile will spawn a bit behind the bullet spawn point, Its hard to explain the problem, so here’s a link to the game: https://www.roblox.com/games/6927193723/Gun-system
Please play the game before giving a solution to the problem.
Looks to me that you are creating the bullets on the server. The reason for the bullet appearing to lag behind is due to replication delay because of information from the client being sent to the server and vice versa.
There’s nothing much you can do about it really, you could do some lag compensation (this is a headache and still won’t fix it fully).
If the game is going to be competitive then I would recommend firing bullets on the client instead (Yes this will make it vulnerable to exploits, but having the replication delay will ruin the experience on competitive games).
When you fire a bullet on the client, you will have to use a remote event that sends the details to the server, which then sends that to each client so they can replicate it too.
When you fire a bullet on the client, you also fire a remote event to the server, containing the target position or direction.
Once the server receives this you then want to send that info to all clients. You don’t want the client who sent the remote to receive it though.
You could do something along the lines of:
OnServerEvent:Connect(function(playerWhoFired, targetPosition)
for _, player in ipairs(players) do
if player ~= playerWhoFired then
remote:FireClient(player, targetPosition)
end
end
end)
Each client will know the player who fired and the target position. So then each client can then create a new projectile starting at the player’s character, going in the direction of target position.
When the client recieves the player who fired along with the target position, you could treat the player.Character.PrimaryPart.Position as the spawn point for example
OnServerEvent:Connect(function(playerWhoFired, targetPosition)
for _, player in ipairs(players) do
if player ~= playerWhoFired then
remote:FireClient(player, playerWhoFired, targetPosition)
end
end
end)
Then on the client,
OnClientEvent:Connect(function(playerWhoFired, targetPosition)
--create a bullet at playerWhoFired.Character and make it move torwards targetPosition
end)
But targetPosition is the mouse, right? So then how would I define the gun that the player who fired the bullet is holding, so I can set the bullet Starting Position?
EDIT:
Ah, I see. So, I would have to do something like this? PlayerWhoFired.Backpack.Gun.BulletSpawnPoint, to set the starting position for the bullet.
There’s a lot of flexibility in how you do this. For the sake of simplicity I would just have the bullet spawn in the middle of the character, or at their head like a lot of FPS games do, if you wanted you could also find the gun model inside the character and have it spawn there.
I was assuming targetPosition would be the Mouse.Hit.Position. If you are doing something else you can just make it anything that will indicate a direction or target position for the bullet to travel to.
When the gun is equipped it will be in the character model, it’s only in the backpack when unequipped. If you are having it spawn at the gun then you will also need to do checks in case the gun was unequipped before the remote event reaches the client.
Thanks for the help! It now works fine, It fixed the problem and it doesnt have any replication delay, and it also fixed the Network Ownership problem that I had, I marked your first reply as the solution, Thanks