Hello, I’m making a script for a gun but the gun is not working.
Error in console: Attempt to compare boolean and number
LocalScript:
local player = game.Players.LocalPlayer
local CharacterPlayer = player.Character or player.CharacterAdded:Wait()
local Mouse = player:GetMouse()
local Ammo = 5
local AmmoLeft = 5
local MaxDistance = 70
local Equipped = false
local Reloading = false
script.Parent.Equipped:Connect(function()
Equipped = true
game.ReplicatedStorage.Ammo:Fire(player, Ammo)
Mouse.Icon = "rbxasset://textures/MouseLockedCursor.png"
end)
script.Parent.Unequipped:Connect(function()
Equipped = false
game.ReplicatedStorage.AmmoUnequipped:Fire(player)
Mouse.Icon = "rbxasset://textures/ArrowFarCursor.png"
end)
Mouse.Button1Down:Connect(function()
local Target = Mouse.Target
local HumanoidPlayer = CharacterPlayer:FindFirstChild("Humanoid")
if Target.Parent:FindFirstChild("Humanoid") and AmmoLeft >= 1 and Equipped and not Reloading
and (Target.Parent.HumanoidRootPart.Position -
CharacterPlayer.HumanoidRootPart.Position).magnitude <= MaxDistance then
local Character = Target.Parent
local Humanoid = Character:FindFirstChild("Humanoid")
if not Humanoid.Health <= 0 and not HumanoidPlayer.Health <= 0 then
AmmoLeft = AmmoLeft -1
script.Parent.Handle.FireSound:Play()
game.ReplicatedStorage.LessAmmo:Fire(player)
script.Parent.TakeDamageEvent:FireServer(Character)
elseif not Target.Parent:FindFirstChild("Humanoid") and AmmoLeft >= 1 and Equipped and not
HumanoidPlayer.Health <= 0 and not Reloading then
AmmoLeft = AmmoLeft -1
script.Parent.Handle.FireSound:Play()
game.ReplicatedStorage.LessAmmo:Fire(player)
elseif AmmoLeft == 0 and Equipped and not HumanoidPlayer.Health <= 0 and not Reloading then
Reloading = true
game.ReplicatedStorage.Reload:Fire(player)
script.Parent.Handle.Reload:Play()
wait(3)
AmmoLeft = Ammo
Reloading = false
end
end
end)
It seems that the error is in that line:
if not Humanoid.Health <= 0 and not HumanoidPlayer.Health <= 0 then