Currency accumulation with attributes not working

error out of nowhere keeps popping up and i don’t know how to fix this, so i’m counting on yall

first script, controls tile functions; called "localstudtiles"
located inside StarterPlayerScripts

-- just a heads up, greyed out stuff like this comment means its irrelevant to the problem

-- 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')
				
				coinsvalue += studtile:GetAttribute("CoinsProduction")
				studsvalue += studtile:GetAttribute("StudsProduction")
				
				--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()

==================================================================================================
second script, manages values for currencies; called "resourceshandler"
located inside a screengui within StarterGui

local coinsbalance = script.Parent.resourceframes.coinsframe.coinsbalance
local coinsvalue = coinsbalance:FindFirstChild('coinsvalue')
local persecondincome = script.Parent.resourceframes.coinsframe.persecondincome

local studsbalance = script.Parent.resourceframes.studsframe.studsbalance
local studsvalue = studsbalance:FindFirstChild('studsvalue')
local persecondincome2 = script.Parent.resourceframes.studsframe.persecondincome2

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

basecoinsincome = 1
basestudsincome = 1

function naturalresourcesgain()
	while true do
		wait(1)
		coinsvalue.Value += basecoinsincome
		coinsbalance.Text = coinsvalue.Value
		persecondincome.Text = "+"..basecoinsincome.."/s"
		

		wait()
		studsvalue.Value += basestudsincome
		studsbalance.Text = studsvalue.Value
		persecondincome2.Text = "+"..basestudsincome.."/s"
	end
end

when the function is called after clicking on a stud tile this error pops up on output
the error i keep getting

value per tick still refuses to change, still on base income which is 1, even though the stud tile is already claimed as well as the attributes having been updated from zero-zero to 2 and 1, which should make it to 3 coins and 2 studs produced per second if it worked properly



according to my relative inexperience either its because i forgot about

GetAttributeChangedSignal()

or i need to duplicate the aforementioned values into ReplicatedStorage (maybe? idk)

but either way im not good at this man my scripting knowledge is only 3 months old so if yall can help me out i can at least learn something
P.S. make it quick, i just wanna make a retro-style grand strategy game here man

Classic mistake, forgot .Value (we all do this :cry:

3 Likes

you’re defining coinsvalue and studsvalue as instances (presumably numbervalues)

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')

and then you’re trying to add a number attribute to the value you defined as an instance (which causes the error)

coinsvalue += studtile:GetAttribute("CoinsProduction")
studsvalue += studtile:GetAttribute("StudsProduction")

try changing it to this:

coinsvalue.Value += studtile:GetAttribute("CoinsProduction")
studsvalue.Value += studtile:GetAttribute("StudsProduction")
1 Like

HOW DID I MISS THIS
thanks though, works again

1 Like

real solution already found in

so closing this

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.