Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't this work?

Asked by 9 years ago

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

Log in to vote
0
Answered by 9 years ago

Close! Humanoid is not directly under the player, but rather under the characterof 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)


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. NotsoPenguin 705 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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)

Answer this question