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

Health depletion script not depleting health?

Asked by 6 years ago
Edited 6 years ago

I decided to make a health depletion script for a nuclear winter game. However, when I try to run it in game, nothing happens. I am a beginner and would appreciate if somebody told me what I am doing wrong.

local depletionAmount = 10

local function healthDeplete
    local humanoid = character:FindFirstChild('Humanoid')
    if humanoid then
        local currentHealth = humanoid.Health
        wait (1)
                local newHealth = currentHealth - depletionAmount
        humanoid.Health = newHealth
    end
end
0
Is this your entire script? Azarth 3141 — 6y
0
yes. it is the entire script jakobgomez6 -3 — 6y
0
How do you get the character variable??? lukeb50 631 — 6y

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

You're missing a few vital things. For one, you never defined your character. Two, you didn't put parenthesis after the function name. Three, you never called the function.

It depends how you wanted to use this, but here's an example. This would go in a LocalScript in StarterCharacterScripts.

-- player is the variable that points to the client (the player running the script) in a LocalScript.
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local depletionAmount = 10

local function healthDeplete()
    local currentHealth = humanoid.Health
    -- wait(1)
    local newHealth = currentHealth - depletionAmount
    humanoid.Health = newHealth
end

healthDeplete()
0
Thank you for the help but the thing is I can't get it to loop no matter how many loops I try. jakobgomez6 -3 — 6y
Ad

Answer this question