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

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

Asked by 5 years ago

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?

0
Because the Humanoid has to be inside of a model saSlol2436 716 — 5y

2 answers

Log in to vote
0
Answered by
piRadians 297 Moderation Voter
5 years ago

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
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 ~~~~~~~~~~~~~~~~~ 129Steve129 7 — 5y
0
Don't use WAIT as your condition in infinite loops, use while true do. ^ mixgingengerina10 223 — 5y
0
Why? Vulkarin 581 — 5y
0
For readability purposes and because wait() as your condition is a hack. User#19524 175 — 5y
0
what makes it not readable and uh...what does the hack part mean? Vulkarin 581 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

Answer this question