ServerScriptService.ShopHandler:50: invalid argument #1 to 'find' (table expected, got string)


Server Script

local PLRStats = DataStoreService:GetDataStore("StaffShop")
local datatable = {"Wood_Staff"}
local EquippedStaff
local function onPlayerJoin(player)
	EquippedStaff ="StringValue",player)
	EquippedStaff.Name = "EquippedStaff"
	local playerUserId = player.UserId.." PLR"
	local data
	local success, err = pcall(function()
		data = PLRStats:GetAsync(playerUserId)
	if success then
		if data[1] then
			datatable = data[1]
			if data[2] ~= nil then
				EquippedStaff.Value = data[2]
				EquippedStaff.Value = "Wood_Staff"

local function onPlayerLeave(player)
	local success, err = pcall(function()
		local playerUserId = player.UserId.." PLR"
		local data2send = {datatable,EquippedStaff.Value}
	if not success then


local NotificationRE = game.ReplicatedStorage.Notification
local Module = require(game.ReplicatedStorage.MakeChatMessage)

	local Price = game.ReplicatedStorage.BuyableStaff[tooln].Price.Value
	plr.Money.Value -= Price
	local msg = plr.DisplayName.."(@"..plr.Name..") Just bought "..tooln.." for "..Price
	NotificationRE:FireClient(plr,Color3.fromRGB(187,47,47),-Price.." Money")
	if not table.find(datatable,tooln) then -- error line
	NotificationRE:FireClient(plr,Color3.fromRGB(87,187,87),"+1 "..tooln)

	plr.EquippedStaff.Value = item

I am making a shop system.

And my scripts gives this error and also when I buy something it says the message twice (open the scripts)

this is the error and IDK why and how the table becomes a string! printing the table returns
table: (random stuff) and when I buy a item the script says the message in chat TWICE! or more times depending on how many items I have in the table so can someone solve this problem as I dont know what table: (random stuff) means

datatable = data[1]

You’re overriding datatable here.

1 Like

what do you mean by that?

He means that you are changing the table.

i am changing it into a table but how then does it becomes a string?

Because you are setting the datatable to the first string in data
As stated above, you are doing
datatable = data[1]

can you please send me a fixed code so that i can understand?

Did you read what the scripting support category template even says?

Not to come across as rude, but you haven’t really answered what you want to accomplish, do you want it to not error? Or do you want your output to say what’s inside a table? Please elaborate.

Also, is your item a developer product or a gamepass, because the script that prints the message in the chat twice may be due to a bug.

See how you are setting the table to a singular string value, not a table, what do you specifically want to happen if data[1] exists?

I think there is a typo here, rename datatable to data2send, because datatable only has 1 value anyway.

ok so LISTEN I want no errors OK? and DATA[1] is a table data[2] is a value becuz i am making a shop system and WHERE AM I SETTING my table TO A STRING???

wait ok i understand what you mean but then how do i send both?

I thought data[1] is the first value in the table?

I thought data[2] doesn’t even exist?

You need to change the value you save to the table you want to save, because it doesn’t exist.
Thank you for your understanding and co-operation.
PS: Sorry for the late post.

I actually did got what the problem was thanks but there is another

my scripts send a message twice…

Is your shop item a gamepass or developer product?

its a in game tool item

Since this is getting somewhat off-topic, it’d be preferred if we continue this in PMs or start a new topic.