How to add value on table?

hello so im kinda new at table i need help adding a + value on table

 local Table = {
	["food"] = 4
}
local Result = game:GetService("HttpService"):JSONEncode(Table)

game.Players.PlayerAdded:Connect(function(Player)
	local FoodTableTest = Instance.new("StringValue", Player)
	FoodTableTest.Value = Result
	FoodTableTest.Name = "Food"
end)

workspace.Buy.ClickDetector.MouseClick:Connect(function(Player)
	-- when player clicks it supposed to add +1 value on table = food 
end)
Table["food"] += 1

OR

Table.food += 1
1 Like

Do i need to decode the value of string when adding value

Nope CHAR LIMIT

Yes you do need to decode it, so it would be like this:

local HttpService = game:GetService 'HttpService'

local Table = {
	["food"] = 4
}

local Result = HttpService:JSONEncode(Table)

game.Players.PlayerAdded:Connect(function(Player)
	local FoodTableTest = Instance.new("StringValue", Player)
	FoodTableTest.Value = Result
	FoodTableTest.Name = "Food"
end)

workspace.Buy.ClickDetector.MouseClick:Connect(function(Player)
	local value = HttpService:JSONDecode(Player.Food.Value)
    value.food += 1
    Player.Food.Value = HttpService:JSONEncode(value)
end)
2 Likes

Thankyou bro this is exactly what im lookin for

1 Like