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)
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)
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)