How come the global variable change?

So for some reason the global variable changes and I’m not sure why it’s not a humanoid even though it should…
Script that sends the variable:

Player.Character.HumanoidRootPart.Touched:Connect(function(hit)
	if Debounce == false then
		local TargetHumanoid = hit.Parent:FindFirstChild("Humanoid")
	
		if not TargetHumanoid then return end
	
		Event:FireServer(TargetHumanoid)
		Debounce = true
		wait(Cooldown)
		Debounce = false
	end
	end)
end)

Script that recieves:

local Event = script.Parent:WaitForChild("RemoteEvent")

local Damage = 15

Event.OnServerEvent:Connect(function(TargetHumanoid)

TargetHumanoid:TakeDamage(Damage)

end)

Output:
TakeDamage is not a valid member of Player "Players.SilentSuprion"
Thanks for reading.

The first parameter of OnServerEvent is always the player who fired the event,

Event.OnServerEvent:Connect(function(TargetHumanoid)

Should be

Event.OnServerEvent:Connect(function(_, TargetHumanoid)
1 Like