Gun Doesn't Damage The Target

so i made a gun and uhh everything works except damage.

so in the local script it sends the Mouse.Target.Parent, and when it first failed i made it print the target which it did and it was not nil, then i made it print the humanoid, again not nil.
and then i made it print a message so that i would know if it entered the if statement, which it did.
but it doesn’t damage it.

serverscript;

local Tool = script.Parent

local Connection = Tool:WaitForChild("Connection")

Connection.OnServerEvent:Connect(function(plr,Target)
	print("Fired!!")
	local PossibleHumanoid = Target:FindFirstChildWhichIsA("Humanoid")
	print(Target)--Prints [InsertModelNameHere]
	print(PossibleHumanoid)--Prints "Humanoid"
	if PossibleHumanoid then
		print("Started")--Prints
		PossibleHumanoid.Health -= 175--Doesn't Run
	end
end)

Thanks in advance!

Okay, first, off the bat, don’t use mouse.Target

You should raycast, otherwise when using mouse.Target, it will simply only fire the thing you’re hovering over, so it doesn’t take into account what’s in the line of sight.

But, that’s out of the question, instead of subtracting health, try use PossibleHumanoid:TakeDamage(175), and see what that does. If it still doesn’t work, then see if theres another script changing the health or interfering in some way.

there’s no other script that changes health except for the serverside of the gun.
and with takedamage it still doesn’t do anything

edit: if i raycast do i have to use as destination the mouse.target or what do i use a s destination?

Can you print the health before and after the humanoid is damaged, and send the result?

ok so i printed the health before and after the damage should’ve been taken, the first one says “Nil” and the second one doesn’t print. but the humanoid exists because of the print i used to see if there’s a humanoid

edit: i tested it once more and this time it prints 0 both of times while the humanoid has 100 health

That’s… weird. Can you send your localscript and a picture of the explorer? I’ve never seen this.

localscript:

local Tool = script.Parent

local Player = game.Players.LocalPlayer

local Mouse = Player:GetMouse()

local Connection = Tool:WaitForChild("Connection")

local Cooldown = 15

local Bullets = 25
local BulletCooldown = 3

local Canuse = true

local GunUI = Player.PlayerGui.CREATE_NPC_DIALOG:WaitForChild("GunGUI")
local GunCounter = GunUI:WaitForChild("GunCounter")


Tool.Activated:Connect(function()
	if not Canuse then return end
	
	Canuse = false
	Connection:FireServer(Mouse.Target.Parent)
	if Bullets > 0 then
		Bullets -= 1
		GunCounter.Text = Bullets.."/25"
		task.wait(BulletCooldown)
		
	else
		GunCounter.Text = Bullets.."/25"
		task.wait(Cooldown)
		Bullets = 25
		GunCounter.Text = Bullets.."/25"
	end
	Canuse = true
end)


Tool.Equipped:Connect(function()
	GunCounter.Text = Bullets.."/25"
	Player.CameraMode = Enum.CameraMode.LockFirstPerson
	GunUI.Visible = true
end)

Tool.Unequipped:Connect(function()
	Player.CameraMode = Enum.CameraMode.Classic
	GunUI.Visible = false
end)

picture of print:

It looks like the humanoid is already dead, since it was 0 at the beginning.

i checked and it says 100 health and there’s no way it could’ve died before i shot it

ok so i found the problem, it had something to do (idk what though it looked completely fine) with the humanoid, i ended up having to delete and replace it with a new one.
at least i know it wasn’t because of the gun.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.