I am making a game where you can shoot projectiles. What I want to achieve is to let all the clients see the projectiles with all the particles and let the server see another part without particles. The server will do the touched event to see when there is a hit. The reason for this is to not stress the server and also for the client to see the projectiles fly smoothly. The projectiles use BodyVelocity to move. I chose BodyVelocity because I want the projectiles to have constant speed and it is easy to use in my opinion.
I have a folder called OnlyServer where the projectiles that are created on the server gets parented in. Every player has a local script where there is a ChildAdded event on that folder. In the event I delete the added child.
local OnlyServer = workspace:WaitForChild('OnlyServer')
OnlyServer.ChildAdded:Connect(function(child)
game.Debris:AddItem(child, 0)
end)
The problem is that the projectiles gets stuck on the server after 30-45 seconds running the game for some reason I don’t understand. The projectiles fly for some studs and then they get stuck. The script below creates the projectiles.
while wait(0.5) do
local proj = game:GetService('ReplicatedStorage').Proj:Clone()
proj.Position = Vector3.new(math.random(1,10), math.random(1,10), math.random(1,10))
proj.Parent = workspace.OnlyServer
game.Debris:AddItem(proj, 50)
end
The GIF above shows the projectiles getting stuck.
The GIF above shows that when moving them in studio they will move again, but only for 2-3 seconds before getting stuck again.
If you add a Touched event to all projectiles and you move the projectile in studio on the server it will update the projectiles that are close to it. What happens is that the projectiles that are close moves too and then they get stuck.
The GIF above shows projectiles close to the moved projectile being updated when all the projectiles has a Touched event.
Another detail I found was that if I remove the line where the part gets deleted and add a print instead, the parts will no longer get stuck. But after 30-45 seconds they will start to freeze for under a second and then move normally.
The GIF above shows the projectiles freezing for under a seconds and then moving normally again.
I also tried a different method, by doing a FireAllClients with the projectile that got created and then deleting it on the client, but same things happen.
The part has a BodyVelocity and is unanchored with CanCollide off. I have tried changing the BodyVelocity’s MaxForce and P to inf. The same problems occur both in Studio and in-game.
My quesion is if I am missing something or if there is some other way to achieve the same result? I think it is strange, since the server shouldn’t be caring about what happens in a local script. I would like to use BodyVelocity since it is simple. There’s the VectorForce, but I don’t understand it and same problems could happen with that too. If I can’t find the fix for this problem, I could try TweenService, but I think it will be difficult to create a projectile with constant speed. One thing that I don’t want to do is to just make the projectiles transparent. The reason for me doing all of this is to not create lag, and making them transparent will not help with that.
This is my game
projectiles_stuck.rbxl (19.9 KB)