-Closed Scipting Issue-

You shouldn’t add the wait(10) in the if statement because it only runs if the hunger value is 0

1 Like

I did that so when it does not spam the output with “Hunger Depleted” every 0.1 secs

Also, why is the title now Script Issue -CLOSED-?

I do agree with certain users in this thread. You should learn basics of LUA first before attempting to make these to have your code more efficient.

I will still give you a complete solve to this.

--VARIABLES
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HungerValue = script.Parent

--CONFIGURATION
local WaitLowerHealth = 60

--LOADER
HungerValue.Value = 50 --I suggest manually doing it to just remove this line

--LISTEN_TOCHANGE
HungerValue:GetPropertyChangedSignal("Value"):Connect(function()
	if HungerValue.Value == 0 then
		Humanoid.Health = 0
	end
end)

--LOWER_HUNGERVALUE_LOOP
while wait(WaitLowerHealth) do
	HungerValue.Value = HungerValue.Value-1
end

I did a GetPropertyChangedSignal so you can also manually change the value from external scripts. If you do not wish for this to occur, you don’t actually need a PropertyChangedSignal and you can merge that into the loop.

2 Likes

I kinda agreed with him :frowning:, im pretty bad at coding. And i understand that: its done now, i will try finish it, or scrap it, i dont know yet.

1 Like

so, i have came to the conclusion, and i have scrapped the game…

You’re not bad, just new. Please don’t take anything that we in this thread, especially I, have said as discouraging or to say you shouldn’t code. We are happy to help you along your journey learning to code in LUA and programming will take you a long way the longer you stay invested in it. It’s just that your current level of experience needs some work, and the only way to get that beginner experience is to be helped along by tutorials or videos to understand how to do things correctly before trying them yourself.

The basic LUA tutorial articles on things such as loops, functions, ect will help you a long way to understand what your code is actually doing. If you need some guidance or have questions after reading some articles and learning a bit more fundamentals, feel free to shoot me a message and I’ll do what I can to answer questions as well.

1 Like

I’m just going to stick to modeling from now on, I have some experience with it so I guess it would suit me more. I don’t think scripting really is for me, I rarely do it. You didn’t discourage me, to be fair I wasn’t motivated to script in the first place, it was more of a me problem.