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

16:29:08.624 - ServerScriptService.Script:31: attempt to index nil with 'Name'?

Asked by 3 years ago

So i wanna make a tp command(from an alvin blox video)

but it say this : 16:29:08.624 - ServerScriptService.Script:31: attempt to index nil with 'Name'

the code :

local commands = {}

local admins = {"m6xw"}

local prefix = "?"

local function findPlayer(name)

    for _, player in pairs(game.Players:GetPlayers()) do
        if string.lower(player.Name) == name then
            return player
        end
    end

    return nil

end

local function isAdmin(player)
    for _, v in pairs(admins) do
        if v == player.Name then
            return true
        end
    end

    return false
end

commands.tp = function(sender, arguments)

    print("TP function fired by "..sender.Name)

    for _, playerName in pairs(arguments) do
        print(playerName)
    end

    local playerToTeleportName = arguments[1]
    local playerToTeleportToName = arguments[2]

    if playerToTeleportName and playerToTeleportToName then
        local playerToTP = findPlayer(playerToTeleportName)
        local playerToTPTo = findPlayer(playerToTeleportToName)

        if playerToTP and playerToTPTo then
            playerToTP.Character.HumanoidRootPart.CFrame = playerToTPTo.Character.HumanoidRootPart.CFrame
            print("Moved successfully")
        end

    end

end

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message,recipient)
        message = string.lower(message)

        if isAdmin(player) then

        local splitString = message:split(" ")

        local slashCommand = splitString[1]

        local cmd = slashCommand:split(prefix)

        local cmdName = cmd[2]

        if commands[cmdName] then

            local arguments = {}

            for i = 2, #splitString, 1 do
                table.insert(arguments,splitString[i])
            end

                commands[cmdName]()

            end
        end

    end)
end)
0
This might work ~~~~~~~~~~~~~~~~~ above this line print("TP function fired by "..sender.Name) ~~~~~~~~~~~~~~~~~ put this line ~~~~~~~~~~~~~~~~~ if sender.Name then ~~~~~~~~~~~~~~~~~ Philipceo90 18 — 3y
0
This might work ~~~~~~~~~~~~~~~~~ above this line print("TP function fired by "..sender.Name) ~~~~~~~~~~~~~~~~~ put this line ~~~~~~~~~~~~~~~~~ if sender.Name then ~~~~~~~~~~~~~~~~~ Philipceo90 18 — 3y
0
this is HARD tttvbb 2 — 3y

Answer this question