Projectile motion offset

Hello, I would like to know how I can remedy the following problem: my projectiles are in the right direction, etc., when I am not moving, but if they are not moving, how can I make sure that they are in the right position all the time?

rs.Events.Boat.TurretFire.OnServerEvent:Connect(function(player)
	local boat = player:FindFirstChild("currentBoat")
	if boat and boat.Value then 
		boat = boat.Value

		local projectiles = {}

		for _, towerMainModel in pairs(boat:GetChildren()) do 
			if towerMainModel:IsA("Model") and towerMainModel.Name:sub(1,5) == "Tower" then
				local towerModel = towerMainModel.Tower

				for _, shootPart in pairs(towerModel:GetChildren()) do
					if shootPart:IsA("Part") and shootPart.Name == "ShootPart" then

						local projectile = Instance.new("Part")
						projectile.Parent = workspace
						projectile.Shape = Enum.PartType.Ball
						projectile.Size = Vector3.new(0.8,0.8,0.8)
						projectile.Position = shootPart.Position
						projectile.Anchored = false
						projectile.CanCollide = false
						projectile.Material = Enum.Material.Neon
						projectile.Color = Color3.fromRGB(255, 132, 1)
						projectile.Name = player.Name.."_shoot_"..boat.Name
						projectile.Transparency = 1

						table.insert(projectiles, {part = projectile, direction = shootPart.CFrame.LookVector})

						local effect = shootPart:FindFirstChild("Effect")
						local sound = shootPart:FindFirstChild("SFX")
						if effect then 
							effect.Enabled = true
						end
						if sound then
							sound:Play()
						end
					end
				end
			end
		end
		
		task.wait(0.05)
		for _, data in pairs(projectiles) do
			local speed = 1000
			data.part.Transparency = 0
			data.part.Velocity = data.direction * speed
		end

		task.wait(0.3)
		for _, towerMainModel in pairs(boat:GetChildren()) do 
			if towerMainModel:IsA("Model") and towerMainModel.Name:sub(1,5) == "Tower" then
				local towerModel = towerMainModel.Tower
				for _, shootPart in pairs(towerModel:GetChildren()) do
					local effect = shootPart:FindFirstChild("Effect")
					if effect then 
						effect.Enabled = false
					end
					local sound = shootPart:FindFirstChild("SFX")
					if sound then
						sound:Stop()
					end
				end
			end
		end

		for _, data in pairs(projectiles) do
			game:GetService("Debris"):AddItem(data.part, 2)
		end
	end
end)

sorry, can you reword the issue a bit? I’m not really getting it.

Watch this video:

still a bit confused, what is is currently doing, and what is it meant to do?
like the original wording was just a bit confusing.

You see when I shoot? There are balls that leave the turrets, and well when the boat is not moving, it is straight and it leaves the turret gun, and there when I am moving it is a little to the right for example if I move forward, in fact the time that it fires and that I move forward and well a period of time passes and it does not leave at the right moment.

Oh, yeah I see now. Sounds like its just a ping issue with the boat’s position on the client being ahead of it on the server, and the server replicates the projectile from the point which the turret is on the server (plus some extra distance ontop of that for the ping for the server to replicate to the client that the projectile was made)
I haven’t really read the script, but I see a few waits, so if those are made before the projectile is made, that could make the problem worse (but skimming I don’t think you did that)

I have one idea to solve this though, Every time you fire your own gun, it basically just makes the projectile like it does on the server, but its just for show and doesn’t actually do anything. Still have the projectiles on the server, and have them visible for all players, but in a local script make it so it hides/deletes projectiles that were replicated from server to client if those projectiles were fired by your own gun as soon as the projectiles appear.
Rough and probably somewhat sloppy solution, but should have the effect without giving client any authority over projectiles or anything.

Uh I didn’t understand sorry :(.

Have two projectiles, one on the server, one on the client. The client deletes or hides the version of its projectile on the server using childadded() or something.
Making instances on the client means only your client can see the projectile, and then you just delete or hide the second other projectile (the one that will be offset from the turret on your screen) on the client, which will only be deleted/hidden on your client and not others as well.
Only do the client side copy thing for your own projectiles obviously instead of for every player whenever any projectile is fired.

Uh, it couldn’t be simpler :(… it seems very long and complex to me for something like this, and if it was because of a delay, it’s true that here we can clearly see that the shot doesn’t start immediately. They appear immediately and do not leave.

Honestly not really, just have some easy way to know what projectiles are from what ship, tags, folders, whatever, then just copy and paste the projectile logic to the client with some stuff stripped, and have something connected to childadded() and instantly delete or hide any projectiles shot by you.

Another thing is the wait between when you create the projectile Part and all it’s properties (why not just have the projectile Part already set up and clone it?) you parent it to the workspace. Then task.wait(.05) seconds later you give it speed.


No find other things; thanks team.