hi, i made a gun script that has a objectvalue that test if that value has a humanoid. if it does it removes some health. but it won't damage anything? please help!
local plr = game.Players.LocalPlayer
local char = plr.Character
local target = script.Parent.Target
local tracking = false
local canuse = true
local mouse = plr:GetMouse()
script.Parent.Equipped:Connect(function()
tracking = true
end)
while wait() do
if tracking == true then
target.Value = mouse.Target
end
end
script.Parent.Activated:Connect(function()
if target.Value.Parent.Humanoid ~= nil then
target.Value.Parent.Humanoid.Health = target.Value.Humanoid.Health-10
end
end)
script.Parent.Unequipped:Connect(function()
tracking = false
end)

3 comments
How can an object be nil?
it tests if the object isn't nil (aka ~=)
Not apart of the problem, but you use :TakeDamage(damage) instead to make decreasing health simpler