Hi all,

How do I update the values stored in an array?

local clicked = script.Parent.Parent.ClickDetector
local price = script.Parent.Frame.title
	local pp = {tonumber(price.gems.Text), tonumber(price.gold.Text), tonumber(price.food.Text), tonumber(price.stone.Text), tonumber(price.wood.Text), tonumber(price.premiums.Text)}
local canAfford = true

clicked.MouseClick:connect(function(playerClicked) 
	local rss = playerClicked.PlayerGui:WaitForChild("resources")
		local rp = {tonumber(rss.wallet_gems.Value), tonumber(rss.wallet_gold.Value), tonumber(rss.wallet_food.Value), tonumber(rss.wallet_stone.Value), tonumber(rss.wallet_wood.Value), tonumber(rss.premiums.Value)}
				for i = 1, 6, 1 do
			if pp[i]>rp[i] then
				print(pp[i] .. " larger than " ..rp[i])
				canAfford = false
			else print(pp[i] .. " OK")
			end
		end
	
	print("clicked by " .. playerClicked.Name)
	
	if canAfford == true then
		print("YAY")
	else print("nooo")
		canAfford = true
	end
end)

I'd like to make the rp table update its values when a click is detected. At the moment the values are logged when the player enters (I've just tested, they dont even have to click to log the values, which is weird?? idk) but do not update when the part is clicked.

Thank you for your help!

2 comments

0

I suck with math and tables, so I can't help you. But, why is your variable called "pp" xD

0

Big PP energy ofc. Nah idk, just because "price" was taken and i couldnt think of anything else lmao