Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can't define player, any help?

I'm trying to define "plr", but I keep getting the error "attempt to index local 'plr' (a nil value)".

The error is on line 10.

Hierarchy: Lowest Descendant to Highest Descendant

Script

Create

Frame

Application

PlayerGui

Player

local create = script.Parent
local frame = create.Parent
local id = frame.groupID
local plr = script.Parent.Parent.Parent.Parent.Parent

local ap = require(game.Workspace.TrelloAPI)


create.MouseButton1Click:connect(function(plr)
    if plr:GetRankInGroup(tonumber(id.Text)) == 255 then
        local group = game:GetService("GroupService"):GetGroupInfoAsync(tonumber(id.Text))
        local BoardID = ap:GetBoardID("Appalachian Security Contract Application")
        local ListID = ap:GetListID("Applied",BoardID)

        local id = id.Text

        local CardID = ap:AddCard("[NS] " .. group.Name, plr.Name, id, ListID)
		print("He's the owner!!!!")
		wait(3)
	plr:Kick("Thank you for choosing Appalachian Private Security Company, we hope you choose us again! -APSC")
	script.Parent.Parent.create.Visible = false
    else
		print("He's NOT the owner!!!!")
        script.Parent.Parent.Warn.Visible = true
		script.Parent.Parent.create.Visible = false
		script.Parent.Parent.groupID.Text = "Sorry, you MUST be the owner!"
		script.Parent.Parent.groupID.TextColor3 = script.Parent.Parent.groupID.TextColor3(255, 0, 0)
		wait(5)
		script.Parent.Parent.groupID.Text = "Enter group ID here"
		script.Parent.Parent.groupID.TextColor3 = script.Parent.Parent.groupID.TextColor3(0, 0, 0)
    end
end)

1 comment

0

Sadly there are no parameter for the mouse that define a player (always nil). Instead, you can grab the player's mouse, using "player:GetMouse" (more on the "mouse" object ----> http://wiki.roblox.com/index.php?title=API:Class/Player/GetMouse)

1 answer

✓ Accepted answer

Odds are, you are be doing this from a LocalScript (if not, you should). Therefore, you can just do this to get the player:

local plr = game.Players.LocalPlayer

Also, you seem to be doing a lot of repetition. Instead of script.Parent.Parent.Warn.Visible You can do frame.Warn.Visible instead.

local create = script.Parent
local frame = create.Parent
local id = frame.groupID
local plr = game.Players.LocalPlayer

local ap = require(game.Workspace.TrelloAPI)


create.MouseButton1Click:connect(function(plr)
    if plr:GetRankInGroup(tonumber(id.Text)) == 255 then
        local group = game:GetService("GroupService"):GetGroupInfoAsync(tonumber(id.Text))
        local BoardID = ap:GetBoardID("Appalachian Security Contract Application")
        local ListID = ap:GetListID("Applied",BoardID)

        local id = id.Text

        local CardID = ap:AddCard("[NS] " .. group.Name, plr.Name, id, ListID)
        print("He's the owner!!!!")
        wait(3)
    plr:Kick("Thank you for choosing Appalachian Private Security Company, we hope you choose us again! -APSC")
    script.Parent.Parent.create.Visible = false
    else
        print("He's NOT the owner!!!!")
        frame.Warn.Visible = true
        create.Visible = false
        frame.groupID.Text = "Sorry, you MUST be the owner!"
        frame.groupID.TextColor3 = script.Parent.Parent.groupID.TextColor3(255, 0, 0)
        wait(5)
        frame.groupID.Text = "Enter group ID here"
        frame.groupID.TextColor3 = script.Parent.Parent.groupID.TextColor3(0, 0, 0)
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.