so i made this gun script for my working gun but when i tested it it didnt work so can anyone help me find the problem
local gun = script.Parent
local bulletSpawnPoint = gun:WaitForChild("BulletSpawnPoint")
local bulletTemplate = game.ReplicatedStorage:WaitForChild("Bullet")
local mouse = game.Players.LocalPlayer:GetMouse()
local function shoot()
local bullet = bulletTemplate:Clone()
bullet.Parent = game.Workspace.Bullets
bullet.Position = bulletSpawnPoint.Position
local direction = (mouse.Hit.p - bulletSpawnPoint.Orientation).Unit
bullet.Velocity = direction * 150
bullet.Touched:Connect(function(hitPart)
local hitCharacter = hitPart:FindFirstChild("Humanoid")
if hitCharacter and hitCharacter.Health > = 1 then
hitCharacter.Health -= math.random(10,25)
if hitCharacter.Health < = 0 then
hitCharacter.Died:Fire()
hitPart.Parent:Destroy()
end
else
print("Hit something that is not a player")
end
wait(2)
bullet:Destroy()
end)
end
gun.Activated:Connect(shoot)