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

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

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

✓ Accepted answer

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)

1 comment

0

thank you it works now

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