I have recently been working on a projectile gun for a game. However, I have ran into some complications, which I wish to hopefully solve through this post.
Moving the bullet: Most tutorials say to use something like BodyVelocity, and I found that it was deprecated. I checked Instance.Velocity, and that was also deprecated. What is the current method for moving objects?
How does one handle actual collisions of projectiles and objects? My main issue is that I do not wish for an exploiter to simply change the script in the bullets, if they can even do that. Do I use BasePart.Touched for collisions, or is there a better method?
Lastly, how do I make it seem smooth? I hear that you should use FireAllClients to handle physics, but I cannot understand how that works. Won’t that cause an event that causes damage to fire multiple times because of how many clients there would be?
I personally would just move the bullet each frame and rayCast to detect if it hit anything. The only way to 100% prevent hacking the bullet logic is by making the bullets server sided (using scripts instead of localScripts).
You can solve all of the problems with a pre-made module named fast cast made for projectile weapons. The module helps you handle the moving (even accounting for realistic physics) and collisions.
Is there a guide I can use that helps understand what modules are? Is this like a module script? Or is this like some sort of global function that can be called in any script?
Physics bullets can always be exploited. So i would say just set the Networkownern of the part to nil and use something like Zoneplus to detect collision idk
The tutorial explains everything well and all you have to call the global function inside the module. I don’t suggest writing your own projectile script as the fast cast already used some advanced methods to remove lag and server/client problems for you.
I ended up following this tutorial, only thing I can’t figure out is how to use CastTerminating to remove the bullet afterwards. There doesn’t appear to be any Bullet parameter passed to that function, atleast on the FastCast website https://etithespir.it/FastCastAPIDocs/fastcast-objects/caster/
The problem is that sometimes the bullet may not actually hit something, so I can’t really on using the Hit event to destroy the bullet. Also, I solved the damage problem by putting an IntValue in the bullet itself
If you can’t use the hit event, you can reference the bullet directly. When the fast cast runs, the module will create a folder called “BulletFolder” in the workspace. If you want to destroy all bullets, you can call :ClearAllChildren() on the folder. If you want the bullet to destroy after a certain time, you can use the ChildAdded event to track the bullet and use the debris service like debris:AddItem(bullet,time)