Projectiles getting stuck in mid-air

I scripted a bow and arrow, but for some reason the projectile becomes anchored in mid air. Here’s my script:
(“arrowClone” is just an unanchored, ball-shaped part. “position” is the position of where the arrow should start, “force” is the force applied to move the ball, “upForce” is a force applied to reduce gravity on the part so it takes more time to fall)

fireArrowEvent.OnServerEvent:Connect(function(plr, position, force, upForce)
	local arrow = arrowClone:Clone()
	arrow.Position = position
	arrow.Parent = workspace
	arrow:SetNetworkOwner(nil)
	local bf = Instance.new("BodyForce", arrow)
	bf.Force = Vector3.new(0, upForce * arrow.AssemblyMass,0)
	arrow:ApplyImpulse(force * arrow.AssemblyMass)
	local connection
	connection = arrow.Touched:Connect(function(hit)
		if hit.Parent ~= plr.Character and hit.Parent.Parent ~= plr.Character then
			print("Hit", hit.Name)
			arrow.Anchored = true
			connection:Disconnect()
		end
	end)	
end)

As shown in the video below, the output prints that the arrow hit the object. For some reason the game thinks that the arrow has touched the part, while to the player it looks like it’s still in midair. Also when I used the exact same code but spawned the arrow from the client, it worked fine, so the issue has to do with the server.

Video of the problem

Any ideas on what could be the problem?

Edit: I tried setting the network ownership to the player who fired it. It looked right from the player’s end, but to the server it still looked like it stopped in mid air.

I can’t think of what the issue could be at this moment. idk but use raycasting instead of a touched event.

Have you seen which parts it thinks the ball has collided with?

It thinks the ball is colliding with the correct part. For example if I aim it at the part named “Dirt”, the output prints “Dirt”. I tried switching the network ownership to the player who fired the arrow, and now it works for that player, but for the server and the rest of the players it lags behind.

Perspective of the player who fired it:
Screen Shot 2022-07-15 at 11.17.26 AM

Perspective of the server:

(The server thinks the part was anchored just before touching the ground, while the client correctly sees it as hitting the ground).

This is a bit of a random attempt but perhaps try setting these right at the end of the function i.e after you make the body mover.

The only other thing that springs to my mind is using raycasting and some kind of custom replication which seems a bit overkill.

1 Like

Perhaps it’s the jank of the roblox touched event? Have you tried using raycasts or spacial queries?

3 Likes