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

Why does name doesn't work on local player? (SOLVED!!)

Asked by 4 years ago
Edited 4 years ago

So, basically I am trying to make a admin command but whenever I say "game.Players.LocalPlayer.Name" it always get a error called "attemp to index nil with "Name""

Here is the whole code:

local prefix = "/"
local targettokick 
local admins = {"scooter369","airstrike0103"}

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)

        local messagesplit = message:split(" ")
        local splittoo = messagesplit[1]:split("/")
        splittoo[2] = string.lower(splittoo[2])


        if splittoo[2] == "kick" then
            for i, v in pairs(admins) do
                if game.Players.LocalPlayer.Name == v then
                    print("Player admin")
                else
                    print("player not admin")
                end
            end             
            targettokick = messagesplit[2] 
            if game.Players:FindFirstChild(targettokick) then
                game.Players[targettokick]:Kick("You have been kicked from the game..")
            end
        end
    end)
end)

If you want to get in the line where I get the error, Go to line 15..

help pls

0
Is it in a local script spunkworks 110 — 4y
0
instead of game.Players.LocalPlayer == v try player.Name == v, since you've already got the player from the playeradded event Warphi 51 — 4y
0
its not in local script InspireWithFun 9 — 4y
0
Thank you Warphi. InspireWithFun 9 — 4y
View all comments (3 more)
0
Nope, Now it always says that player is not an admin. InspireWithFun 9 — 4y
0
I messed up the script and it works now, thank you all anyways, InspireWithFun 9 — 4y
0
Is it just me or do I see a extra 'end)' in the code? Prime_Jayden 11 — 4y

Answer this question