How do i make a "sanity" bar?

34 views Asked by At

I'm trying to make a value stored in the player that starts at 100 and decrements until equal to 0, and once equal to 0, the player dies.

local players = game:GetService("Players")
local plr = players.LocalPlayer.Character
local sanity = plr.Sanity.Value
local hum = plr:FindFirstChild("Humanoid")

while sanity > 0 do
    if sanity == 0 then
        hum.Health = 0
    end
    wait(0.05)
    sanity -= 1
    print(sanity)
end

The problem is that even though the value exists, it is not decrementing it or printing the new value.

I don't know where do start so I haven't tried much, It's supposed to decrement the value every second and kill the player once the value == 0

edit: i found a different way to do it that works perfectly fine

0

There are 0 answers