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

What is wrong with my script? bad argument #2 to 'sub' (number expected, got no value)

Asked by 6 years ago
function guicreate(Player, Text)
    local sg = Instance.new("ScreenGui")
    local fr = Instance.new("Frame")
    local text = Instance.new("TextLabel")
    sg.Parent = game.Players[Player].PlayerGui
    fr.Size = UDim2.new(1, 0,0, 100)
    fr.Position = UDim2.new(0, 0,-1.417, 0)
    fr.Parent = sg
    text.Size = UDim2.new(1, 0,1, 0)
    text.Position = UDim2.new(-2, 0,0, 0)
    text.Parent = fr
    fr.Style = "DropShadow"
    text.BackgroundTransparency = "1"
    text.TextScaled = true
    text.TextColor3 = Color3.new(255, 248, 248)
    text.TextStrokeTransparency = "0"
    text.Text = Text
    fr:TweenPosition(UDim2.new(0, 0,0.417, 0), "Out", "Quad", 3)
    wait(1)
    text:TweenPosition(UDim2.new(0, 0,0, 0), "Out", "Quad", 3)
    wait(2)
    text:TweenPosition(UDim2.new(-2, 0,0, 0), "Out", "Quad", 3)
    wait(3)
    fr:TweenPosition(UDim2.new(0, 0,-2.417, 0), "Out", "Quad", 3)
    wait(2)
    sg:Destroy()
end

local Adminlist = "Kwok6140", "Player1", "Player2"


game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        guicreate(player.Name, "Welcome to this Airport ,"..player.Name)
        player.Chatted:connect(function(msg)
            print(string.sub(string.lower(msg),1,6))
            print(":kill")
            print(string.sub(string.lower(msg),1,6) == "kill")
            if string.lower(msg) == ":kill" or  string.lower(msg) == ":kill me" then
                print("Kill")
                if player.Name == Adminlist then
                    game.Workspace[player.Name].Head:Destroy()
                else
                    guicreate(player.Name, "Sorry,You don't had power to use that command")
                end
            elseif string.sub(string.lower(msg),1,6) == string.sub(string.lower(":kill me"),1,6) then
                print(string.sub(string.lower(msg),1,6))
                if player.Name == Adminlist then
                    local realwhojust = string.sub(msg),6,40
                    if game.Workspace:FindFirstChild(realwhojust) then
                        game.Workspace:FindFirstChild(realwhojust).Head:Destroy()
                    else
                        guicreate(player.Name, ("Sorry,There had no Player Call '"..string.sub(string.lower(msg),6,40).."'"))
                    end 
                else
                    guicreate(player.Name, "Sorry,You don't had power to use that command")
                end
            elseif string.lower(msg) == ":refresh" or  string.lower(msg) == ":refresh me" or string.sub(string.lower(msg),1,9) == string.sub(string.lower(":refresh me"),1,9) then
                print("Refresh")
                if player.Name == Adminlist then
                    game.Workspace[player.Name].Humanoid.Health = 0
                    game.Players.Kwok6140:LoadCharacter()
                else
                    guicreate(player.Name, "Sorry,You don't had power to use that command")
                end
            end
        end)
    end)
end)

I said: :kill Kwok6140

Output:

13:03:30.244 - Workspace.Script:70: bad argument #2 to 'sub' (number expected, got no value)
13:03:30.244 - Stack Begin
13:03:30.245 - Script 'Workspace.Script', Line 70
13:03:30.245 - Stack End

1 answer

Log in to vote
0
Answered by 6 years ago

line 49: local realwhojust = string.sub(msg),6,40

umm, you put the numbers OUTSIDE the (), so you basically defined alternatives instead of parameters

fix: local realwhojust = string.sub(msg, 6, 40)

Ad

Answer this question