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

Why is my hunger decreaser script not working right?

Asked by 4 years ago

I am trying to make a hunger decreaser script, but its taking too much hunger away when I eat, this only occurs when I eat. I think it may have something to do with resetting.

Hunger Decreaser Script:

hunger = "Hunger"
while true do
    wait(20)
    for i,v in pairs(game.Players:GetPlayers())do
        if v:FindFirstChild("leaderstats") then
            v.leaderstats[hunger].Value = v.leaderstats[hunger].Value - 1
        end
    end
end

Eating script:

food = "Food"
hunger = "Hunger"
script.Parent.MouseButton1Click:Connect(function()
    for i, v in pairs(game.Players:GetPlayers())do
        if v:FindFirstChild("leaderstats")then
            if v.leaderstats[food].Value == 0 then print("error") else
            if v.leaderstats[hunger].Value == 20 then print("error")
        else if v.leaderstats[hunger].Value + 5 > 20 then v.leaderstats[hunger].Value = 20 
            v.leaderstats[food].Value = v.leaderstats[food].Value - 1 else
                v.leaderstats[hunger].Value = v.leaderstats[hunger].Value + 5
                v.leaderstats[food].Value = v.leaderstats[food].Value - 1
                    end
                end
            end
        end
    end
end)
0
maybe cause you are full greatneil80 2647 — 4y
0
Try repeat wait() until v:FindFirstChild("leaderstats") OnaKat 444 — 4y
1
^ redundant. Same thing but worse as WaitForChild pidgey 548 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

There's a solution: YOU NEED TO USE GUI'S. 2 frames, 1 text label but not box under the frames. Red frame is "HungerBacking" and Green frame is "HungerBar". Green is the top-priority bar.

There is the code for the "Hunger" bar in your screen;

while true do
    script.Parent.HungerBar.Size = UDim2.new(script.Parent.HungerBar.Size.X, script.Parent.HungerBar.Size.Y - 5)
    wait(1)
end

PLEASE note that the size of the bar should be {0,10},{0, 100} for it to properly work.

Now to the textlabels. 1. Turn on TextScaled 2. Change the size to {0, 55},{0, 25} 3. Set BackgroundTransparency to 1 (Turns off the boring black border) 4. Make the TextLabel say "Hunger" 5. For the position, set position to {0.015, 0},{0.187, 0}

Now we need a tool that upscores your Hunger. We'll call it "Fruit" 1. Make a part called "Handle". Shortcut to rename: Press F2 during the instance focused (clicked). 2. Add a script called "HungerAction". 3. In the script, delete the default script and paste the following:

local Tool = script.Parent;

enabled = true




function onActivated()
    if not enabled  then
        return
    end

    enabled = false


    local hb = game.Players.LocalPlayer.PlayerGui.ScreenGui.HungerBarr.HungerBar
    Tool.Handle.DrinkSound:Play() --make it sound like drink

    wait(3)

    local h = Tool.Parent:FindFirstChild("Humanoid")
    if (h ~= nil) then
        if (h.MaxHealth > h.Health + 5) then
            hb.Size.Y = hb.Size + 5
            h.Health = h.Health + 5
        else    
            h.Health = h.MaxHealth
        end
    end

    Tool.GripForward = Vector3.new(-.976,0,-0.217)
    Tool.GripPos = Vector3.new(0.03,0,0)
    Tool.GripRight = Vector3.new(.217,0,-.976)
    Tool.GripUp = Vector3.new(0,1,0)

    enabled = true

end

function onEquipped()
    Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)
  1. This will hold up our hunger thing. Now to the next thing that edits the mouse cursor;
local MOUSE_ICON = 'rbxgameasset://Images/Large Cursor Click'
local RELOADING_ICON = 'rbxgameasset://Images/Large Cursor (1)'

local Tool = script.Parent

local Mouse = nil

local function UpdateIcon()
    if Mouse then
        Mouse.Icon = Tool.Enabled and MOUSE_ICON or RELOADING_ICON
    end
end

local function OnEquipped(mouse)
    Mouse = mouse
    UpdateIcon()
end

local function OnChanged(property)
    if property == 'Enabled' then
        UpdateIcon()
    end
end

Tool.Equipped:connect(OnEquipped)
Tool.Changed:connect(OnChanged)

This is gonna take up the icon. Have fun using the Hunger GUI!

0
You can edit the "wait(5)" to bigger or lower. ArtyomAL3X 12 — 4y
Ad

Answer this question