Is this effective and how could I improve it. [Bullet-Path Workaround]

Hello, I am at the stage in my game where I am working on the enemy npcs.
Currently the majority of the enemy npcs will use a firearm of some sort, and with my current scripting knowledge the easiest and most logical way to implement the weapon’s path would be to…

Attach a part to the end of the firearm. Adjust the length of the part depending on the weapon. (Shotgun = shorter part, Sniper = longer part)
Turn CanCollide to false. Set the Transparency to 1. And insert a script that would damage the player. And then insert a 2nd script that would Enable/Disable the damage script along with sounds etc.
+Another script that would face the npc towards the closest player.

NPC = game.Workspace.NPC --named npc just to be simple

Part = game.Workspace.NPC.Gun.Part --the part that would damage the player if touching

damageScript = NPC.Gun.Part.DamageScript


while true do

--play reload sound

wait(0.5)

--play gunfire sound

damageScript.Enabled = true

wait(5) --just a random number

damageScript.Enabled = false

--stop gunfire sound

end

I would also obviously add a debounce,

Is this an effective way of creating a bullet path with a relatively low amount of scripting knowledge?
I imagine that it would be easy to create bullet drop considering the damage is being dealt from a part,
and I could just implement a muzzle flash/ smoke to indicate the gun being fired.

Any reply would be greatly appreciated. :grinning:

I see a few things
you add too many spaces and lack proper indentation

1 Like

First, this should be in #help-and-feedback:code-review

Second, Having a script for damaging an enemy player and having another script to toggle that damage script is not good, just have one script. Why two?

Third, when you can, always make your variables local variables, they are faster to reference.
Like so;

local Part = game.Workspace.NPC.Gun.Part

P.S: Use task.wait() it’s more precise

2 Likes