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
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()