-- I tried this.
local cursor = workspace.Part.ClickDetector
local part = script.Parent
local human = script.Parent:FindFirstChild("Humanoid")
function onClick()
if human then
human.Health = 0
end
end
cursor.MouseClick:Connect(onClick)
-- I added a clickDetector
✓ ANSWER ACCEPTED
How to kill player when you click a part?
2 answers
✓ Accepted answer
you are trying to define the Humanoid inside the part, not the player that clicked it.
Here's how you fix that :
local cursor = workspace.Part.ClickDetector
function onClick(player)
local human = player.Character.Humanoid
if human then
human.Health = 0
end
end
cursor.MouseClick:Connect(onClick)
local clickDetector = script.Parent
local function onClick(playerClicked)
local character = playerClicked.Character
if (character) then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if (humanoid) then
humanoid:TakeDamage(humanoid.Health)
end
end
end
clickDetector.MouseClick:Connect(onClick)
This discussion is preserved as it was. New answers, comments, and votes are closed.
