I have a part that gives the player a tool, and it does that just fine. However, I want it to be so that, when the player clicks this part, they take 10 damage every few seconds or so (in the script I’ll provide it says 3 but I’m likely to change it later) until they lose all 100 health.
I’m pretty sure I’ve got it right, but I think I’ve messed up somewhere since it doesn’t work. I think it’s something to do with the fact I’m trying to call the player’s Humanoid
from the MouseClick
function, but I don’t really know.
I’m not getting any console errors from this, so anyone know what’s up?
(If there’s an easier way to do this do let me know, as well.)
local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
ClickDetector.MouseClick:connect(function(Player)
if Player.Parent:FindFirstChild("Humanoid") ~= nil then
local char = Player.Parent
char:WaitForChild('Humanoid').Health -= 10
wait(3)
char:WaitForChild('Humanoid').Health -= 10
wait(3)
char:WaitForChild('Humanoid').Health -= 10
wait(3)
char:WaitForChild('Humanoid').Health -= 10
wait(3)
char:WaitForChild('Humanoid').Health -= 10
wait(3)
char:WaitForChild('Humanoid').Health -= 10
wait(3)
char:WaitForChild('Humanoid').Health -= 10
wait(3)
char:WaitForChild('Humanoid').Health -= 10
wait(3)
char:WaitForChild('Humanoid').Health -= 10
wait(3)
char:WaitForChild('Humanoid').Health -= 10
wait(3)
char:WaitForChild('Humanoid').Health -= 10
end
end)