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

why isn't this script working even though there was no error?

Asked by 3 years ago

there's no error it just wasn't doing what it's meant to do.

repeat
    wait(1)
    for i, player in ipairs(game.Players:GetPlayers()) do
        if player.Character then
            local hum = player.Character:FindFirstChild('Humanoid')
            hum.Health -= 1
        end
    end
until 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

(hunger script)

script.Parent.MouseClick:Connect(function(g)
    if g.Character then
        local hum = g.Character:FindFirstChild('Humanoid')
            hum.Health += 10
    end
    script.Parent.Parent:Destroy()
end)

(food script)

neither of these work. if i remove "if __.Character then end" it will error.

i already removed the auto regen.

1 answer

Log in to vote
0
Answered by 3 years ago

In Lua the -= and += operators are not defined. You need to write it as

hum.Health = hum.Health - 1

Also the repeat until 9999... is quite messy. Instead, use while wait(1) do instead since you are placing the wait in the repeat anyways.

while wait(1) do
    for i, player in ipairs(game.Players:GetPlayers()) do
        if player.Character then
            local hum = player.Character:FindFirstChild('Humanoid')
            hum.Health =  hum.Health - 1
        end
    end
end

For the next script I'm assuming it would be a food item or something in the workspace. You would need a clickdetector on the 'food' item.

I would place a script into the part or food that will be clicked on.

local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = script.Parent
ClickDetector.MaxActivationDistance = 5 --player has to be close to eat

local click = script.Parent.ClickDetector

click.MouseClick:Connect(function(player)
    if player.Character then
        local hum = player.Character:FindFirstChild('Humanoid')
        hum.Health = hum.Health + 10
    end
    script.Parent:Destroy()
end)
0
thank you it works now fullguyblox3 69 — 3y
Ad

Answer this question