Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Food consume script gets ignored by starving script?

Asked by
lazolv 7
1 year ago

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

0
why did the first script get lined and second one didnt lol lazolv 7 — 1y
0
Please fix the script showing because I can't read it at all MattVSNNL 620 — 1y

1 answer

Log in to vote
0
Answered by
enes223 327 Moderation Voter
1 year ago

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

0
oh uh I I forgot I posted about my problem here, I already fixed it myelf. Sorry for wasting your time lazolv 7 — 1y
Ad

Answer this question