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

How i can set max grow on Player? My script not work...

Hi guys, i have one problem on this script:

replicatedStorage.Simulator.Test.OnServerEvent:Connect(function(player)

	if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
	
	local debounce = remoteData[player.Name].Debounce
	
	if not debounce.Value then
				
		debounce.Value = true
		
		if player.leaderstats.Power.Value < 3000 then
	
			player.leaderstats.Power.Value = player.leaderstats.Power.Value + 1 * (player.leaderstats.Rebirths.Value + 1)
		
			player.leaderstats.Money.Value = player.leaderstats.Money.Value + math.random(1,4) * (player.leaderstats.Rebirths.Value + 1)
		
		elseif player.leaderstats.Power.Value >= 3000 then
			
			player.leaderstats.Power.Value = player.leaderstats.Power.Value + 0
		
			player.leaderstats.Money.Value = player.leaderstats.Money.Value + math.random(1,4) * (player.leaderstats.Rebirths.Value + 1)
		
		wait(cooldown)
		
		debounce.Value = false
		else
		end
		
	end
	
end)

Works only the first time, in the second "punch" i not receive power and money.

Sorry for bad english

1 answer

✓ Accepted answer

It would seem that you reset your debounce inside the elseif section. Debounce should be reset outside the if elseif else end section.

replicatedStorage.Simulator.Test.OnServerEvent:Connect(function(player)

	if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end

	local debounce = remoteData[player.Name].Debounce

	if not debounce.Value then

		debounce.Value = true

		if player.leaderstats.Power.Value < 3000 then

			player.leaderstats.Power.Value = player.leaderstats.Power.Value + 1 * (player.leaderstats.Rebirths.Value + 1)

			player.leaderstats.Money.Value = player.leaderstats.Money.Value + math.random(1,4) * (player.leaderstats.Rebirths.Value + 1)

		elseif player.leaderstats.Power.Value >= 3000 then

			player.leaderstats.Power.Value = player.leaderstats.Power.Value + 0 --this line is not necessary, but you may want to leave it for clarity

			player.leaderstats.Money.Value = player.leaderstats.Money.Value + math.random(1,4) * (player.leaderstats.Rebirths.Value + 1)

		else --this else is not needed

		end

		--move this two lines
		wait(cooldown)
        	debounce.Value = false

	end

end)

Have a nice scripting session!

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