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

For some reason, this mana script I created isn't working the way it's intended, can someone help?

 -- Mana increase script.
	mana.Changed:Connect(function()
	while mana.Value < manac.Value do -- Manac is the capacity of mana one can have.
		wait(4)
		mana.Value = mana.Value + 10
	end
	if mana.Value > manac.Value then
		mana.Value = manac.Value
	end
-- Basically a textbutton that increases exp and decreases mana when clicked, in the form of a remote event
	game.Players.PlayerAdded:Connect(function(player) 
game.ReplicatedStorage.ExpUp.OnServerEvent:Connect(function()
	local exp = player:WaitForChild("Leaderstats")["Exp"]
	local mana = player:WaitForChild("Mana")
	local manac = player:WaitForChild("Manac")
	if mana.Value >= 5 then
	exp.Value = exp.Value + 20
	mana.Value = mana.Value - 10
		end
	end)
end)

1 comment

0

Basically, whats going on is, every time I click the button, it adds on a new command to increase the mana every 4 seconds, and I only want this command to be done once.

1 answer

✓ Accepted answer

the problem seems to be that ExpUp event changes the mana, which fires the whole mana regeneration part from the beginning, i would remove the mana.Changed() function as it only calls regeneration over and over every time the mana amount changes,

while mana.Value < manac.Value do
end

could be replaced with:

while true do
	wait(4)
	if mana.Value < manac.Value then
		 mana.Value = mana.Value + 10
		if mana.Value > manac.Value then
       			mana.Value = manac.Value
  		end
	end
end

hope this helps!

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