local clickdetector = workspace.Part.ClickDetector local function onMouseClick(otherPart) local partParent = otherPart.Parent local humanoid = partParent:FindFirstChild("Humanoid") if humanoid then humanoid.Health = 0 end end clickdetector.MouseClick:connect(onMouseClick)
I want the code to set humanoid's health to 0 when clickdetector is fired but nothing happens. Any fix?
my dude MouseClick events gives you the player not the "otherPart" so to get the player's character make a variable inside the function like this:
local clickdetector = workspace.Part.ClickDetector local function onMouseClick(player) local char = player.Character or player.CharacterAdded:Wait() -- character of the player local humanoid = char:FindFirstChild("Humanoid") -- the humanoid if humanoid then humanoid.Health = 0 end end clickdetector.MouseClick:connect(onMouseClick)