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

'Attempt to index boolean with 'Cost"?

I am making a shop for my simulator and I have this error: ' attempt to index boolean with 'Cost' '

local RS = game:GetService("ReplicatedStorage")
local thisData = RS:WaitForChild('GetCacheData'):InvokeServer('Foods', script.Parent.Name)

script.Parent.MouseButton1Click:Connect(function()
	assert(thisData ~= nil, "NO DATA FOUND FOR "..script.Parent.Name)

	script.Parent.Parent.SelectedItemFrame.Name.Text = thisData.Name --This is the line with the error
	script.Parent.Parent.SelectedItemFrame.Price.Text = "$"..thisData.Cost -- This one also gives the error
end)

This is the second script:

local remote = game:GetService("ReplicatedStorage"):WaitForChild('GetCacheData')
local storage = game:GetService("ServerStorage")
local Cache = require(storage:WaitForChild('CacheData'))
local timeout = 5
local logged = {}

remote.OnServerInvoke = function(player, kind, ...)
	if not player or not kind then return false end
	if tick()-(logged[player.UserId] or 0) < timeout then return false end
	local thisCache = Cache[kind]
	
	if #{...} < 1 then return thisCache end
	for _, k in pairs({...}) do
		thisCache = thisCache[k] or thisCache
	end
	
	logged[player.UserId] = tick()
	return thisCache
end

And this is the script with all of the data:

return {
	Foods = {
		Apple = {
			Name = 'Apple',
			id = 1,
			Weight = 5,
			Cost = 0,
		},
		Burger = {
			Name = 'Burger',
			id = 4,
			Weight = 500,
			Cost = 2000,
		},
		ChocolateBar = {
			Name = 'ChocolateBar',
			id = 2,
			Weight = 20,
			Cost = 150,
		},
		Fries = {
			Name = 'Fries',
			id = 6,
			Weight = 3000,
			Cost = 25000,
		},
		Pizza = {
			Name = 'Pizza',
			id = 5,
			Weight = 1250,
			Cost = 10000,
		},
		Sandwich = {
			Name = 'Sandwich',
			id = 3,
			Weight = 35,
			Cost = 400,
		},
		Steak = {
			Name = 'Steak',
			id = 8,
			Weight = 8000,
			Cost = 2000000,
		},
		Taco = {
			Name = 'Taco',
			id = 7,
			Weight = 4500,
			Cost = 60000,
		},
	},
	Bags = {
		SmallPicnicBack = {
			Name = "Small Picnic Back",
			id = 9,
			Capacity = 15,
			Cost = 0,
		},
		RegularBag = {
			Name = "Regular Bag",
			id = 10,
			Capacity = 30,
			Cost = 100,
		},
		LargeBag = {
			Name = "Large Bag",
			id = 11,
			Capacity = 50,
			Cost = 275,
		},
		Backpack = {
			Name = "Backpack",
			id = 12,
			Capacity = 80,
			Cost = 500,
		},
		Suitcase = {
			Name = "Suitcase",
			id = 13,
			Capacity = 130,
			Cost = 925,
		}
	},
}

2 comments

0

Is the variable "thisdata" a boolean?

0

My cousin made the scripts and won't respond to me asking the same question, so idk

1 answer

You could try thisData["Cost"] and thisData ["Name"] instead? It shouldn't really make a difference but it's worth a try!

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