Currency accumulation with attributes not working 2

ah sheet, here we go again

continued from

false flag solution from earlier post, the solution I marked was for setting the base income only with natural growth and NOT the actual accumulation, since then I have removed the solution from the first topic and the topic is reopened

I’ve edited the second script so now it looks like this after a few failed solutions. The base income refuses to change when I claim a stud tile still, but I tried one edit that surprisingly resulted in the opposite - the accumulation surprisingly worked, but in reverse; instead of increasing when I claim tiles, it decreases from the maximum to zero income per second if I claim all tiles (since then i’ve scrapped that version)

If you’re wondering where I put the values in, they’re parented with TextLabels within StarterGui;
Is that normal or do I have to move them to ReplicatedStorage?

local coinsbalance = script.Parent.resourceframes.coinsframe.coinsbalance
local coinsbalancevalue = coinsbalance:FindFirstChild('coinsbalancevalue')
local persecondincomelabel = script.Parent.resourceframes.coinsframe.persecondincome
local coinspersecondincome = persecondincomelabel:FindFirstChild('coinspersecondincome')

local studsbalance = script.Parent.resourceframes.studsframe.studsbalance
local studsbalancevalue = studsbalance:FindFirstChild('studsbalancevalue')
local persecondincomelabel2 = script.Parent.resourceframes.studsframe.persecondincome2
local studspersecondincome = persecondincomelabel2:FindFirstChild('studspersecondincome')

local player = game.Players.LocalPlayer
local CollectionService = game:GetService("CollectionService")

basecoinsincome = ""
basestudsincome = ""

function naturalresourcesgain()
	basecoinsincome = 1
	basestudsincome = 1
	while true do
		wait(1)
		workspace.SFXFolder.timebombtick:Play()
		coinsbalancevalue.Value += coinspersecondincome.Value + basecoinsincome
		coinsbalance.Text = coinsbalancevalue.Value
		persecondincomelabel.Text = "+"..basecoinsincome + coinspersecondincome.Value.."/s"
		

		wait()
		studsbalancevalue.Value += studspersecondincome.Value + basestudsincome
		studsbalance.Text = studsbalancevalue.Value
		persecondincomelabel2.Text = "+"..basecoinsincome + studspersecondincome.Value.."/s"
	end
for _, studtile in CollectionService:GetTagged("HighlightableTiles") do
		local clickdetector = studtile:FindFirstChild("ClickDetector")
		if studtile:IsA('Part') and studtile.Name == "4x4studtile" then
				if studtile:GetAttribute("Ownership") == player.Name then
					--coinsvalue.Value += studtile:GetAttribute("CoinsProduction")
					--studsvalue.Value += studtile:GetAttribute("StudsProduction")
					while true do						
					local newcoinspersecondincome = coinspersecondincome.Value + studtile:GetAttribute("CoinsProduction")
					local newstudspersecondincome = studspersecondincome.Value + studtile:GetAttribute("StudsProduction")
					
						local newcoinsincome = basecoinsincome + studtile:GetAttribute("CoinsProduction")
						local newstudsincome = basestudsincome + studtile:GetAttribute("StudsProduction")
						
					coinspersecondincome.Value = newcoinspersecondincome
					coinsbalancevalue.Value = basecoinsincome + newcoinsincome
					
					studspersecondincome.Value = newcoinspersecondincome
					studsbalancevalue.Value += basestudsincome + newstudsincome
					
					persecondincomelabel.Text = "+"..newcoinspersecondincome.."/s"
					persecondincomelabel2.Text = "+"..newstudspersecondincome.."/s"
					
					print("added")
					return 
					end
				elseif studtile:GetAttribute("Ownership") == "[nil]" then
					print("not owned")
					
					coinsbalancevalue.Value += coinspersecondincome.Value + basecoinsincome
					coinsbalance.Text = coinsbalancevalue.Value
					persecondincomelabel.Text = "+"..coinspersecondincome.Value.."/s"
					
					studsbalancevalue.Value += studspersecondincome.Value + basestudsincome
					studsbalance.Text = studsbalancevalue.Value
					persecondincomelabel2.Text = "+"..studspersecondincome.Value.."/s"
				else
					print("the hell?")
				end
			end
		end
	end

naturalresourcesgain()

if the issue is in the first script with the clickdetectors (in the first post) you may include that as well

I’m not even sure what this is about cz i lose focus easily on long texts but that while loop will cause the code after it to not run.

2 Likes

tried that many times, the values just stop counting after a few ticks

and if i merge the rest of the code into the while true do loop it results in the reverse accumulation

Is the error still on line 47? or has the line changed when you modified the script code

1 Like

Can you explain what you’re trying to do in a nutshell? Also, whats the click detector variable for if u never use it? You can make the while loop run inside a task.spawn so it doesn’t interrupt other code

1 Like

the line has already changed it doesnt print any errors

To confirm, the issue is that the accumulation decreases when all tiles are claimed? Sorry if I misunderstood

1 Like

i’ll delete the click detector local later its meant for the other script

thats if i merge the for _, studtile with the while true do loop

printing in place to check for the problem

print('added') only prints once for a single tile, the other 8 do not


red for control color as claim
and the values froze after i clicked on one tile

So only one tile has been recognised by the script and contributed to the production?

1 Like

the tile was recognized but didnt add to production, instead just broke the entire thing

if you need the first script from the first post here it is

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local target = mouse.Target
local CollectionService = game:GetService("CollectionService")
local selectr = true

local function updatemechanism()

	for _, studtile in CollectionService:GetTagged("HighlightableTiles") do
		local clickdetector = studtile:FindFirstChild("ClickDetector")
		local studinfogui = player.PlayerGui:FindFirstChild("studinfogui")
		local startingpointgui = player.PlayerGui:FindFirstChild("startingpointgui")
		if studtile:IsA('Part') and studtile.Name == "4x4studtile" then
			local UIBUTTONCLICK = game.Workspace.SFXFolder.UI_BUTTON_CLICK
			clickdetector.MouseClick:Connect(function()
				selectr = true
				UIBUTTONCLICK:Play()
				
				-- studtile.Color = Color3.fromRGB(255, 0, 0)
				local studnametext = studtile:FindFirstChild("StudnameText")
				local ownershiptext = studtile:FindFirstChild("OwnershipText")
				local mouseoverguilabel = game.StarterGui.mouseovergui.TextLabel
				studnametext.Value = "4x4 Stud Tile"
				ownershiptext.Value = "" .. player.Name .. ""
				
				local ownership_display = player.PlayerGui.studinfogui.nameframe.ownership_display
				local studname_display = player.PlayerGui.studinfogui.nameframe.studname_display
				local nameframe = player.PlayerGui.studinfogui.nameframe
				local editabletextbox = studname_display:FindFirstChild('editabletextbox')

				ownership_display.Text = "Owned by: " .. player.Name
				studname_display.Text = "4x4 Stud Tile"
				nameframe.BackgroundColor3 = studtile.Color
				editabletextbox.BackgroundColor3 = studtile.Color
				
				studtile:SetAttribute("Ownership", player.Name)
				studtile:SetAttribute("CoinsProduction", 2)
				studtile:SetAttribute("StudsProduction", 1)
				
				--local coinsbalance = player.PlayerGui.resourcesgui.resourceframes.coinsframe.coinsbalance
				--local coinsvalue = coinsbalance:FindFirstChild('coinsvalue')
				
				--local studsbalance = player.PlayerGui.resourcesgui.resourceframes.studsframe.studsbalance
				--local studsvalue = studsbalance:FindFirstChild('studsvalue')
				
				--local persecondincome = player.PlayerGui.resourcesgui.resourceframes.coinsframe.persecondincome
				--local persecondincome2 = player.PlayerGui.resourcesgui.resourceframes.studsframe.persecondincome2
				
				--coinsvalue.Value += studtile:GetAttribute("CoinsProduction")
				--studsvalue.Value += studtile:GetAttribute("StudsProduction")
				
				--persecondincome.Text = "+"..studtile:GetAttribute("CoinsProduction").."/s"
				--persecondincome2.Text = "+"..studtile:GetAttribute("StudsProduction").."/s"
				
				studinfogui.Enabled = true
				startingpointgui.Enabled = false
				editabletextbox.Visible = true
				
			end)
		else 
			selectr = false
			studinfogui.Enabled = false
			-- editabletextbox.Visible = false
			
		end

	end
end

mouse.Button1Down:Connect(updatemechanism)
updatemechanism()

To be clear, just so I understand the game:
In this game, you claim tiles which increase the gain of currency? To claim a tile, you click on it

1 Like

for now yes, it’s going to be a retro-style grand strategy game or an rts, - there will be political functions and military mechanics later

for now this will be the basis of a player nation’s economy

and definitely claim cooldowns because the map is finite

I think

while true do						
					local newcoinspersecondincome = coinspersecondincome.Value + studtile:GetAttribute("CoinsProduction")
					local newstudspersecondincome = studspersecondincome.Value + studtile:GetAttribute("StudsProduction")
					
						local newcoinsincome = basecoinsincome + studtile:GetAttribute("CoinsProduction")
						local newstudsincome = basestudsincome + studtile:GetAttribute("StudsProduction")
						
					coinspersecondincome.Value = newcoinspersecondincome
					coinsbalancevalue.Value = basecoinsincome + newcoinsincome
					
					studspersecondincome.Value = newcoinspersecondincome
					studsbalancevalue.Value += basestudsincome + newstudsincome
					
					persecondincomelabel.Text = "+"..newcoinspersecondincome.."/s"
					persecondincomelabel2.Text = "+"..newstudspersecondincome.."/s"
					
					print("added")
					return 
					end

Returning before the end of a while true ends the function completely, stopping the natural resource gain function from happening. I would recommend removing the while loop as the code will only run once anyway , and I think it should work

1 Like

it works but now it broke lol

Ah, so like the numbers are out of proportion?

1 Like

yea both the balance value and income per tick increased automatically (only the balance should increase automatically, the income per tick should only increase as more tiles are claimed