Projectile lags for a second when I instantiate it

So I was scripting a game where you can throw items around… The problem that I was having was when I instantiated a projectile it would lag for a second and then it will start moving

This only started happening after I started rendering on the server-side. I already tried using something call PCache and I don’t really want to get into restarting my code for FastCast. Is there any other way to fix this?
Here is an example:

2 Likes

Have you tried setting the network ownership? Learn more Here.

1 Like

I tried doing that too but I got an error when I did that. Ill show you in a sec

1 Like

Alright so I set the network owner to nil and there is no error outputting but the freezing is still there
image

1 Like

By the way don’t use instance .new with a second arguement.

I believe you need to set the properties first then parent it into the workspace since I believe the delay is due to the delay in setting the velocity of the projectile.

3 Likes

Ill try that thanks. ill message back if it does not work

Alright I tried that and nothing changed

Yeah I tried it and nothing changed after following that

are you sure it’s being parented after the velocity is set (instead of before)?

i am sureimage

Maybe anchoring the part and using raycasting to detect the collisions and moving it every frame?

try setting the properties in this order:

- looks (material, color, size, etc.)
- the light
- set network owner to the client who fired it, not “nil”
- physics (cancollide, location, velocity)
- parent

i cant set the network owner before parenting since it has to already be a descendant of workspace

my bad, make sure it isn’t nil though

wdym what should i make it then?

nil sets the ownership to the server

the player who fired the bullet, so it appears smooth for them

if you want, you can call bullet:SetNetworkOwnershipAuto() on it after it reaches a certain distance from the player

yeah but that would not really change anything the freezing will still remain

You can remove the BodyVelocity part and do something like…

local Speed = 5

local Connection
	Connection = RunService.Stepped:Connect(function()
		if not Part then -- Stops moving and disconnects if it doesn't exist anymore
			Connection:Disconnect()
		end
		local ProjectileRay = Ray.new(Part.Position, Part.CFrame.LookVector * Speed)
		local Hit,Position = Workspace:FindPartOnRay(ProjectileRay, Character)
		Part.Position = Part.Position + Part.CFrame.LookVector * Speed
		if Hit then
			-- Do collision logic
			Connection:Disconnect() -- Stops moving as it's collided by now
		end
	end)

It might be useful if it’s related to what I’m seeing. You’d need to adapt it to the way that you’re working on tbh.

Recommended to use the new raycast :wink: