local PLRStats = DataStoreService:GetDataStore("StaffShop")
local datatable = {"Wood_Staff"}
local EquippedStaff
local function onPlayerJoin(player)
EquippedStaff = Instance.new("StringValue",player)
EquippedStaff.Name = "EquippedStaff"
local playerUserId = player.UserId.." PLR"
local data
local success, err = pcall(function()
data = PLRStats:GetAsync(playerUserId)
end)
if success then
if data[1] then
datatable = data[1]
if data[2] ~= nil then
EquippedStaff.Value = data[2]
else
EquippedStaff.Value = "Wood_Staff"
end
wait(0.1)
game.ReplicatedStorage.SendTable:FireClient(player,data)
end
end
end
local function onPlayerLeave(player)
local success, err = pcall(function()
local playerUserId = player.UserId.." PLR"
local data2send = {datatable,EquippedStaff.Value}
PLRStats:SetAsync(playerUserId,datatable)
end)
if not success then
error(err)
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerLeave)
local NotificationRE = game.ReplicatedStorage.Notification
local Module = require(game.ReplicatedStorage.MakeChatMessage)
game.ReplicatedStorage.PlayerBought.OnServerEvent:Connect(function(plr,tooln)
local Price = game.ReplicatedStorage.BuyableStaff[tooln].Price.Value
plr.Money.Value -= Price
local msg = plr.DisplayName.."(@"..plr.Name..") Just bought "..tooln.." for "..Price
Module.SendMessage(msg,Color3.fromRGB(187,107.47),"Shop")
NotificationRE:FireClient(plr,Color3.fromRGB(187,47,47),-Price.." Money")
if not table.find(datatable,tooln) then -- error line
table.insert(datatable,tooln)
end
game.ReplicatedStorage.SendTable:FireClient(plr,datatable)
wait(0.5)
NotificationRE:FireClient(plr,Color3.fromRGB(87,187,87),"+1 "..tooln)
end)
game.ReplicatedStorage.PENI.OnServerEvent:Connect(function(plr,item)
plr.EquippedStaff.Value = item
end)```
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
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???
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.