Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't this work?

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?

2 answers

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)


1 comment

0

First, wait is not a valid method of a model or Humanoid. Second waiting for the character/humanoid does not make sense here as it would kill them after they respawn. Third checking for the Humanoid without FindFirstChild will just cause an error.

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.