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

Problem with this script? [closed]

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
while true do
    if game.Players.LocalPlayer.Character.Humanoid:TakeDamage() then
    script.Parent.Parent.Sounds.Hurt:Play()
    end
end
0
:TakeDamage(n) is a method that takes damage *n* from the Humanoid, not checks if damage was taken. Tkdriverx 514 — 10y

Locked by BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

The TakeDamage method is used to well, take damage. You would put a number as a parameter and the Humanoid would take damage. You need to use the Changed event.

game.Players.PlayerAdded:connect(function(p)
    repeat wait() until p.Character -- You could also use the CharacterAdded event. I for some reason did it this way
    hum = p.Character.Humanoid
    old = hum.Health
    hum.Changed:connect(function()
        if (hum.Health < old) then
            script.Parent.Parent.Sounds.Hurt:Play()
            old = hum.Health
        end
    end)
end)

The above script was actually tested and should work perfectly.

Ad