So, basically, what I am trying to achieve here is making it so that when your hunger bar gets to zero, you get kicked, or you die: it doesn’t matter which one (preferably die).
if script.Parent.Hunger.Value == 0 then
player:kick(“Hunger Depleted”)
end
There are more fundamental issues here and I recommend looking through the beginner documentation on the roblox dev hub to get a grasp of LUA as a language.
I think you should place the check inside of the loop, like this:
while true do
script.Parent.Value = script.Parent.Value - 1
wait(0.1)
if script.Parent.Hunger.Value == 0 then
player:kick(“Hunger Depleted”)
wait(10)
end
end
local player = game.Players.LocalPlayer
spawn(function()
while true do
script.Parent.Hunger.Value = script.Parent.Hunger.Value - 1
wait(0.1)
end
end)
if script.Parent.Hunger.Value == 0 then
player:Kick(“Hunger Depleted”)
end
The loop is infinite and yields the script, so the if statement wont run.
To add to what I said earlier, using RunService | Roblox Creator Documentation instead of constantly checking with a wait will more naturally handle the constant checking of the value for the hunger. However, understanding events, connections, functions, and function arguments is going to be effort if you’re still learning LUA which is why I say to focus on the beginner tutorials provided by ROBLOX.
But, checking an important value on the client is generally bad practice because it opens up the possibility of players exploiting their own client. See: Roblox Client-Server Model
As such, I recommend taking a step back and learning more of what LUA has to offer to get you to a higher level of competency before trying to implement your own complex scripts. There are plenty of tutorials and guiding articles here.
Your code has a plethora of mistakes that are just a result of you being inexperienced, and you need to watch and read more tutorials to understand the fundamentals of programming to better understand everything you did wrong. Even fixing your code in the initial post to make it run will not result in good code, so you have fundamental issues that are just a lack of experience. Nothing personal and it’s just constructive criticism but we won’t be able to help you much on the forum if you are unable to write in LUA at a basic level.