Attempt to modify readonly table help wanted!

Never messed around with tables before so this is confusing to me and there is no table. thing that says make the thing copiable or whatever so help would be appreciated!

The code is :

local plr = game.Players[script.Parent.Parent.Parent.Parent.Name]
local Char = plr.Character
local Monster = Char.IsMonster
local Remaining = script.Parent.Objective.Remaining

local AlreadyKilled = {}

while task.wait() do
	if workspace.RoundStarted.Value == false then
		for i in pairs(table) do
			table[AlreadyKilled] = nil
		end
	end
end

while task.wait() do
	script.Parent.Objective.Text = "Kill "..Remaining.Value.. " Humans as SANS."
	if Monster.Value == true and workspace.RoundStarted.Value == true and plr.MoreData.MonsterType.Value == "Sans" then
		for i,v in pairs(workspace.PlayersPlaying:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("Humanoid") then
				local IM = v:WaitForChild("IsMonster")
				if IM.Value == false then
					repeat task.wait() until workspace.PlayersInRound.Value >=1 
					if v.Humanoid and table.find(AlreadyKilled, v.Name) then
						continue
					else
						table.insert(AlreadyKilled, v.Name)
						task.wait(.5)
						Remaining.Value = Remaining.Value -1
						v.Humanoid.Health = 100
					end
				end
			end
		end
	end
	if Remaining.Value == 0 then
		plr.leaderstats.Gold.Value = plr.leaderstats.Gold.Value + 100
		plr.leaderstats.EXP.Value = plr.leaderstats.EXP.Value + 100
		Remaining:Destroy()
		script.Parent.Objective.Text = ""
		script.Parent.Reward.Text = ""
		script.Parent.Parent.Enabled = false
		plr.MoreData.CurrentQuest.Value = 1
		script:Destroy()
	end
end

The line erroring is line 11

			table[AlreadyKilled] = nil

Help would be greatly appreciated thank you!

1 Like

you can just do, “AlreadyKilled = nil”

You are attempting to index the datatype “table”.
You can’t do for i in pairs(table) do because once again “table” is a roblox lua keyword.

Replace this part:

while task.wait() do
	if workspace.RoundStarted.Value == false then
		for i in pairs(table) do
			table[AlreadyKilled] = nil
		end
	end
end

With this:

while task.wait() do
	if workspace.RoundStarted.Value == false then
		for i,v in pairs(AlreadyKilled) do
			AlreadyKilled[i] = nil
		end
	end
end

I wouldn’t recommend KultDeeri’s solution as it basically removes the entire table, since you want to remove only the contents inside of the table, not the table itself.

2 Likes

Right I forgot that she’ll need it, I just thought she wouldn’t need it anymore. But yeah your solution would work.

1 Like