Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my 'LoopKill' command erroring?

Asked by 9 years ago

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
0
Thanks for giving us just a snippet of the code, but what is the syntax of line 962? bobafett3544 198 — 9y
1
Please edit your question to 1) Indicate what line number the first line is in this snippet; 2) Paste the *full error* *verbatim* into your question BlueTaslem 18071 — 9y
0
Lol, sorry, I forgot to add those, I've just added the Error and what line is '962'. TheeDeathCaster 2368 — 9y

1 answer

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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


Asides

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
0
Wow, I never knew my code was messy, and I can't believe I didn't see that mistake. XD Thanks man! By the way, congrats on 900+! :) TheeDeathCaster 2368 — 9y
0
He'll reach 1k before I know it, he's good at what he does. M39a9am3R 3210 — 9y
0
I've got to admit, I'm really jealous of how much he knows. XD TheeDeathCaster 2368 — 9y
Ad

Answer this question