As the title says, I’m making a raycast gun which works for the most part but has a weird glitch in it, that being that it will not damage anyone who doesn’t have the same health as its damage. (For example, the gun will deal 100 damage. Anyone who doesn’t have exactly 100 Health won’t be killed).
This is the snippet of the code.
local raycast = workspace:Raycast(GunHandle.Position, (MousePOS - GunHandle.Position).Unit * 200)
local hitbox = raycast.Instance
if hitbox then
local char = hitbox.Parent
local Humanoid = char:FindFirstChild("Humanoid")
if Humanoid and char ~= Plr.Character and Humanoid.Health >= 1 then
Humanoid:TakeDamage(384)
if Humanoid.Health <= 1 then
local BodyVelocity = Instance.new("BodyVelocity",char.PrimaryPart)
BodyVelocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
local Dir = (char.PrimaryPart.CFrame.Position - Plr.Character.PrimaryPart.CFrame.Position).Unit
BodyVelocity.Velocity = (Dir + Vector3.new(0, 3, 0)).Unit * 250
game:GetService("Debris"):AddItem(BodyVelocity,.025)
end
end
end
local raycast = workspace:Raycast(GunHandle.Position, (MousePOS - GunHandle.Position).Unit * 200)
local hitbox = raycast.Instance
if hitbox then
local char = hitbox.Parent
local Humanoid = char:FindFirstChild("Humanoid")
if Humanoid and char ~= Plr.Character and Humanoid.Health > 0 then
Humanoid:TakeDamage(384)
if Humanoid.Health <= 0 then
local BodyVelocity = Instance.new("BodyVelocity", char.PrimaryPart)
BodyVelocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
local Dir = (char.PrimaryPart.CFrame.Position - Plr.Character.PrimaryPart.CFrame.Position).Unit
BodyVelocity.Velocity = (Dir + Vector3.new(0, 3, 0)).Unit * 250
game:GetService("Debris"):AddItem(BodyVelocity, 0.025)
end
end
end
work at all? I just changed the if statement. If it doesn’t, try to print out the boolean of every part of the if statement before the damaging, and try to detect if the script even reaches the :Damage() part.
I’ve already somehow found the issue, apparently, a humanoid with a huge amount of health like 10000000000 makes it invincible against the gun for some reason? Idk, but I’ll try this later, thanks!