Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Food consume script gets ignored by starving script?

I have been making starving system in my game and it worked, but when I added some food that increases hunger value once consumed the added value got to be ignored by main script

How this works on paper: player's hunger slowly decreases over time (2), but once a food item is consumed it increases by a medium amount (20)

How this works in reality: after getting hunger value increased, instead of decreasing the new value it ignores it and continues decrasing like nothing happened which leads to losing the amount of hunger the food gave AND starving value (22)

I tried to make some small changes which didnt change anything and adding a new starving script while disabling main one which lead to output error

scripts:

--- HungerService script located in ServerScriptService ---

game.Players.PlayerAdded:Connect(function(Player)

local Hunger = Instance.new("NumberValue", Player)
Hunger.Name = "Hunger"
Hunger.Value = 100

Player.CharacterAdded:Connect(function(Character)
	Hunger.Value = 100
	repeat wait(1)
		Hunger.Value = math.clamp(Hunger.Value - 2, 0, 100)
	until
	Hunger.Value <= 0
	Character.Humanoid.Health = 0
end)

end)

--- Consume script located in player gui (parented to item supposed to be consumed) ---

local Player = game.Players.LocalPlayer local MainFrame = script.Parent.Parent.Parent:FindFirstChild("MainFrame") local ItemFrame1 = script.Parent.Parent:FindFirstChild("ItemFrame") local ItemFrame2 = script.Parent.Parent:FindFirstChild("ItemFrame2") local UserInputService = game:GetService("UserInputService") local Hunger = Player:WaitForChild("Hunger") local HungerService = game.ServerScriptService.HungerService local Key = Enum.KeyCode.Q

UserInputService.InputBegan:Connect(function(InputObject, GameProcessedEvent) if GameProcessedEvent then return end if InputObject.KeyCode == Key and ItemFrame1.ImageLabel.Image == "http://www.roblox.com/asset/?id=7347267826" then if Hunger.Value <= 80 then Hunger.Value = math.clamp(Hunger.Value + 20, 0, 100) end end end)

Since im not good at advanced scripting most of stuff is based on "if" "then" etc statements

2 comments

0

why did the first script get lined and second one didnt lol

0

Please fix the script showing because I can't read it at all

1 answer

✓ Accepted answer

hey you! have you ever heard of enes? if you are in trouble, better call enes!

1 comment

0

oh uh I I forgot I posted about my problem here, I already fixed it myelf. Sorry for wasting your time

This discussion is preserved as it was. New answers, comments, and votes are closed.