I have checked, and rechecked the code, and changed allot of things in it, but I can't figure out what's wrong, the Output says Workspace.XAdminCommandsX's Admin Commands V1:962: String expected
Script 'Workspace.XAdminCommandsX's Admin Commands V1', Line 1006 - upvalue Chat
Script 'Workspace.XAdminCommandsX's Admin Commands V1', Line 1015
, but, I can't figure out how to fix it, here is the code;
if msg:lower():sub(1,9+#Prefix) == Prefix.."loopkill " then local chk = msg:lower():sub(10+#Prefix):find(" ") + 9+#Prefix local plrz = GetPlr(plr,msg:sub(10+#Prefix,chk-1)) local num = tostring(0) if type(num) == "number" and num ~= 0 then num = msg:sub(chk+1) elseif type(num) == "string" and num ~= "" then num = #msg:sub(chk+1) end for i,v in pairs(plrz) do coroutine.wrap(function() if v and v.Character and --[[not ChkAdmin(v.Name,false) and]] LoopKill then local LoopKillPlr = LoopKill:Clone() LoopKillPlr.Parent = game.Workspace LoopKillPlr.Disabled = false LoopKillPlr.Name = "LoopKill-"..v.Name local ConfirmName = Instance.new("StringValue",LoopKillPlr) ConfirmName.Value = v ConfirmName.Name = "loopKill" local Kills = Instance.new("IntValue",LoopKillPlr) Kills.Value = num Kills.Name = "Kills" table.insert(Container,LoopKillPlr) end end)() --This is line 962, this is where the problem is for some reason end end
Lua's line numbering can sometimes be a bit off.
In this case, your code is much messier than it should be.
Here's the same thing with neater spacing, better variable names (and the if
reduced to the one case that always occurs):
if msg:lower():sub(1, 9 + #Prefix) == Prefix.."loopkill " then local chk = msg:lower():sub(10 + #Prefix):find(" ") + 9 + #Prefix local players = GetPlr(plr, msg:sub(10 + #Prefix, chk-1)) local num = #msg:sub(chk + 1) for _, player in pairs(players) do coroutine.wrap(function() if player and player.Character and LoopKill then local LoopKillPlr = LoopKill:Clone() LoopKillPlr.Parent = game.Workspace LoopKillPlr.Disabled = false LoopKillPlr.Name = "LoopKill-" .. player.Name local ConfirmName = Instance.new("StringValue", LoopKillPlr) ConfirmName.Value = player ConfirmName.Name = "loopKill" local Kills = Instance.new("IntValue", LoopKillPlr) Kills.Value = num Kills.Name = "Kills" table.insert(Container, LoopKillPlr) end end)() --This was line 962 end end
I think the problem is probably
ConfirmName.Value = player
Value
ought to be a string, but you are giving it a object. Try using
ConfirmName.Value = player.Name
Your computation of chk
could error when :find
returns nil
.
There's also no reason at all to use coroutines or even a function here where you are.
Also, in the if
, you shouldn't have to check the existence of player
.
if msg:lower():sub(1, 9 + #Prefix) == Prefix.."loopkill " then local chk = msg:lower():sub(10 + #Prefix):find(" ") + 9 + #Prefix local players = GetPlr(plr, msg:sub(10 + #Prefix, chk-1)) local num = #msg:sub(chk + 1) for _, player in pairs(players) do if player.Character and LoopKill then local LoopKillPlr = LoopKill:Clone() LoopKillPlr.Parent = game.Workspace LoopKillPlr.Disabled = false LoopKillPlr.Name = "LoopKill-" .. player.Name local ConfirmName = Instance.new("StringValue", LoopKillPlr) ConfirmName.Value = player ConfirmName.Name = "loopKill" local Kills = Instance.new("IntValue", LoopKillPlr) Kills.Value = num Kills.Name = "Kills" table.insert(Container, LoopKillPlr) end end end