Script Issue with Character

So this script is supposed to find the players gas mask accessory and (in this case) kill them, but it is not finding the character too well even though I have a player parameter, why is this and how do I fix it?

part = script.Parent

part.Touched:Connect(function(otherPart, player)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChild("Humanoid")
	local character = partParent:FindFirstChild("Character")
	local gasmask = player.Character:FindFirstChild("Gas Mask")
	if humanoid and gasmask then
		humanoid.Health = 0
	end
end)
1 Like

Unsure about the use of Character = otherpart.Parent?

Can give the script below a try, may be errors as typed it via mobile.

local Part = script.Parent

Part.Touched:Connect(function(Hit)

local Humanoid = Hit.Parent:FindFirstChild("Humanoid")

if Humanoid then

local GasMask = Humanoid.Parent:FindFirstChild("Gas Mask")

if GasMask then
Humanoid.Health = 0
end

end

end)
2 Likes

You are pure genius my friend, frfr

2 Likes

player is not a valid argument to Touched. If a player indeed did touch the part then otherPart.Parent would be the Character.

Fixed code: (hopefully)

script.Parent.Touched:Connect(function(otherPart)
    local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
    local gasmask = otherPart.Parent:FindFirstChild("Gas Mask")
	
    if (humanoid and gasmask) then
        humanoid.Health = 0
    end
end)

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