Suppose I have a table
{"31,32,33","41,42,43","20,19,18"}
And I want to get rid of one of those strings, lets say "41,42,43".... I tried doing this:
table.remove(ThatTable, Vector3.new(41,42,43)) table.remove(ThatTable, tonumber(41,42,43)) table.remove(ThatTable, tostring(41,42,43)) table.remove(ThatTable, "41,42,43")
It just won't work, could I have some help please?
I have a datastore script that creates a table for me and I am trying to remove the string
For Azarth:
--Datastore:SetAsync(key,{pos,name,otherdata,moredata}) repeat wait() print("Player not yet loaded...") until script.Parent.GetPlayer.Value == true print("Player Loaded") wait(1) local tbl = {} or nil wait(.5) local DataStore = game:GetService("DataStoreService"):GetDataStore("Vector_Saver") local lastPos = Vector3.new(0,0,0) -- getting player for _, v in pairs(workspace:GetChildren()) do if v:FindFirstChild("Player") then local name = v.Player.Value print(name.." has joined the game :D") Plr = game.Players:FindFirstChild(name) end end -- If the datastore has nothing in it, it will error so I am putting 0,0,0 as the starting coordinates repeat wait() until Plr --DataStore:SetAsync(Plr.UserId,tbl) if DataStore:GetAsync(Plr.UserId) == nil then table.insert(tbl,"000") DataStore:SetAsync(Plr.UserId,tbl) else end DataStore:GetAsync(Plr.UserId) -- setting data / saving it for _, v in pairs(DataStore:GetAsync(Plr.UserId)) do print(v) end game.ReplicatedStorage.Events.SavePos.OnServerEvent:Connect(function() if Plr then for _, v in pairs(Plr.HiddenStats.ItemPos:GetChildren()) do lastPos = v.Value table.insert(tbl, tostring(v.Value)) end DataStore:SetAsync(Plr.userId, tbl) else wait() end end) script.Parent.SellEvent.Changed:Connect(function() if Plr then for _, v in pairs(Plr.HiddenStats.ItemPos:GetChildren()) do table.remove(DataStore:GetAsync(Plr.UserId), script.Parent.SellEvent.Pos.Value.X) table.remove(DataStore:GetAsync(Plr.UserId), script.Parent.SellEvent.Pos.Value.Y) table.remove(DataStore:GetAsync(Plr.UserId), script.Parent.SellEvent.Pos.Value.Z) end DataStore:SetAsync(Plr.userId, tbl) else wait() end end) -- end of script :) -- finally got it to work after 4 years :D -- in real game, there is problem with Saving.... DUE TO EveNTS NOT CHANGING IN REAL GAME MODE!
You can only directly 'lookup' a string like that in a dictionary. You'd have to loop through the table otherwise. Here are some options.
local thatTable = {"31,32,33", "41,42,43","20,19,18"} table.remove(thatTable, 2 ) print( unpack(thatTable) ) -- or for i,v in pairs(thatTable) do if v == "41,42,43" then table.remove(thatTable, i) end end -- or thatTable = { ['31,32,33'] = true, ['41,42,43'] = true, ['20,19,18'] = true} thatTable[ '41,42,43' ] = nil for i,v in pairs(thatTable) do print(i) end