So, im making a gun system like Isle game, and it works like this: when u click on a enemy u start aiming at it, then after a certain amount of seconds if the enemy is still in the player’s range it shoots, but idk how to make that part which stops shooting if the enemy goes behind a wall.
Could anyone help me?
The Script
local tool = script.Parent
local remote = tool:WaitForChild("OnShoot")
local shoot_part = tool:WaitForChild("FirePart")
local Config = tool.Config
local Damage = Config.Damage.Value
local SFX = tool:WaitForChild("Handle")
local Particle1 = shoot_part:WaitForChild("Muzzle")
local Shooting = false
remote.OnServerEvent:Connect(function(player, target)
if not Shooting and Config.Ammo.Value > 0 and (player.Character.HumanoidRootPart.Position-target.Position).magnitude <= 100 then
Config.Ammo.Value -= 1
Shooting = true
tool.Aim:FireClient(player)
wait(2)
Particle1.Enabled = true
tool.Shoot:FireClient(player)
target.Parent.ZombieNoid:TakeDamage(25)
wait(0.2)
Particle1.Enabled = false
wait(3)
Shooting = false
end
end)