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

Why does while true do game.Workspace.Humanoid:TakeDamage(100) wait(0) end not work?

I tried the script while true do game.Workspace.Humanoid:TakeDamage(100) wait(0) end ,but when tested it I did not take any damage?

1 comment

0

Because the Humanoid has to be inside of a model

2 answers

The Humanoid is usually located inside a model, not directly in the workspace.

while true do
workspace.Model.Humanoid:TakeDamage(100) --rename "Model" to your NPC name.
wait()
end

5 comments

0

you usually want to make sure you have no script errors (when you die it deletes your character and cant find it and errors) ~~~~~~~~~~~~~~~~~ local playername = "Put Player name here" while wait() do if(workspace:FindFirstChild(playername) ~= nil)then local mymodelplayer = workspace:FindFirstChild(playername) mymodelplayer.Humanoid:TakeDamage(100) end end ~~~~~~~~~~~~~~~~~

0

Don't use WAIT as your condition in infinite loops, use while true do. ^

0

Why?

0

For readability purposes and because wait() as your condition is a hack.

0

what makes it not readable and uh...what does the hack part mean?

I'm gonna explain this as simply as I can.

I'm gonna break it down as well.

  1. Do not use while true do with a wait(0). Instead, use while wait() do

  2. As the other answer states, use the method "TakeDamage", or set the health. workspace.Model.Humanoid:TakeDamage(100)

  3. It is generally easier to put prints in your code, and in some cases(not this one), use a pcall.

EDIT: been informed that this can't error so no need for a pcall, just print the health.

workspace.Model.Humanoid:TakeDamage(100)

print(workspace.Model.Humanoid.Health)

Keep in mind this may not work EXACTLY, as I am writing this in the text and not testing in studio, but play around with this and it should work as you want it to. Happy to help!

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