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

I need to make my mana script don't wen't over to the max mana?

Before my first question gets answered, I still need to fix that sometings wrong with my mana script for my mana gui, My mana wen't over to the max mana. Last time my friend made a mana script for my mana gui but its buggy. Here it is:

while true do
	wait(0.9)
	script.Parent.Mana.Value = script.Parent.Mana.Value +5
	script.Parent.Text = "Mana: "..script.Parent.Mana.Value.."/"..script.Parent.MaxMana.Value
end
script.Parent.Changed:Connect(function()
		if script.Parent.Mana.Value >= 1000 then --if mana went over maxmana then.
			script.Parent.Mana.Value = 1000
			script.Parent.Text = "Mana: "..script.Parent.Mana.Value.."/"..script.Parent.MaxMana.Value
			wait()
		end --this is the thing that won't work,
		if script.Parent.Mana.Value == 0 or script.Parent.Mana.Value <= 1 then --if mana went -100 then.
			script.Parent.Mana.Value = 0
			script.Parent.Text = "Mana: "..script.Parent.Mana.Value.."/"..script.Parent.MaxMana.Value
			wait()
	end
end)

1 comment

0

so and I deleted the mana script from my friend, made a fresh new script (showed the code above) but I don't like the mana wen't over to the max mana.

1 answer

✓ Accepted answer

I believe the reason this is happening is because your code is running lines 1-5 forever. Since you are using while true do, the rest of the script is never run. Instead, you should check to see if your mana is within range inside of the loop, like so:

local mana = script.Parent.Mana
local maxMana = script.Parent.MaxMana
while true do
	if mana.Value < 0 then -- if Mana goes less than 0
		mana.Value = 0 
	elseif mana.Value >= maxMana.Value then -- if Mana goes over MaxMana
		mana.Value = maxMana.Value
	elseif mana.Value < maxMana.Value then 
		mana.Value = mana.Value + 5
	end

	script.Parent.Text = "Mana: " .. tostring(mana.Value) .. "/" .. tostring(maxMana.Value)
	wait(0.9)
end

1 comment

0

I am not sure but, does this work to upgrade maxMana? hmm oh and it worked.

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