I am trying to make a script that functions when the part is clicked.
script.Parent.ClickDetector.MouseClick:connect(function(plr) local name = script.Parent.Parent.Name name = "Hey,"..plr.Name..". Yeah you. I'm gonna punch you for clicking me!" wait(5) plr.Humanoid:TakeDamage(25) name = "Hmm, that didn't feel good enough. LET MEH PUNCH YOU HARDER!"..plr.Name wait(5) plr.Humanoid:TakeDamage(50) name = "Still not dead. TIME FOR FUS RO DAH!!!" wait(5) plr.Humanoid:TakeDamage(1337) name = "That felt better." wait(5) name = "Please don't click me!" end)
It doesn't work, and it says in the output that there is no humanoid. Help?
Close!
Humanoid
is not directly under the player
, but rather under the character
of the player.
script.Parent.ClickDetector.MouseClick:connect(function(plr) local chr = plr.Character or plr.Character:wait() local hum = chr.Humanoid or chr.Humanoid:wait() local name = script.Parent.Parent.Name name = "Hey,"..plr.Name..". Yeah you. I'm gonna punch you for clicking me!" wait(5) hum:TakeDamage(25) name = "Hmm, that didn't feel good enough. LET MEH PUNCH YOU HARDER! "..plr.Name wait(5) hum:TakeDamage(50) name = "Still not dead?!? TIME FOR FUS RO DAH!!!" wait(5) hum:TakeDamage(1337) name = "That felt better." wait(5) name = "Please don't click me!" end)
The Humanoid
is located inside the character and not the player. Also changing the variable name will just change that variable and not the name property. I also checked if the humanoid exists just incase.
local part = script.Parent.Parent script.Parent.ClickDetector.MouseClick:connect(function(plr) if plr.Character:FindFirstChild("Humanoid") then part.Name = "Hey,"..plr.Name..". Yeah you. I'm gonna punch you for clicking me!" wait(5) plr.Character.Humanoid:TakeDamage(25) part.Name = "Hmm, that didn't feel good enough. LET MEH PUNCH YOU HARDER!"..plr.Name wait(5) plr.Character.Humanoid:TakeDamage(50) part.Name = "Still not dead. TIME FOR FUS RO DAH!!!" wait(5) plr.Character.Humanoid:TakeDamage(1337) part.Name = "That felt better." wait(5) part.Name = "Please don't click me!" end end)