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

why doesnt this work?

i want it to add values to the energy value but it doesnt add

local tool = script.Parent
player = game.Players:GetPlayerFromCharacter(tool.Parent)

tool.Equipped:connect(function(Mouse)
	player = game.Players:GetPlayerFromCharacter(tool.Parent)
	local energy = player.PlayerGui.ScreenGui.Frame.Frame.Energy
	Mouse.Button1Down:connect(function()
		if energy.Value ~= 0  then
			energy.Value = energy.Value - 10
		end
	end)
	if energy.Value ~=100 then
		while true do
			energy.Value = energy.Value +1
			wait()
		end
	end
end)

1 comment

0

You put a while true do statement, which will cause the energy to infinitely grow, since you've never broken the loop. Just saying as a little hint, for future reference.

1 answer

Going off of what Shawnyg said, change the while loop to:

while true do
	if energy.Value =100 then
		break()
	end
	energy.Value = energy.Value +1
	wait()
end

1 comment

0

i think the () adter break isnt supposed to be there but im not sure. just try taking them away if that doesnt work.

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