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

Can't define player, any help?

Asked by 8 years ago

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)
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) LateralLace 297 — 8y

1 answer

Log in to vote
1
Answered by
XAXA 1569 Moderation Voter
8 years ago

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)

Ad

Answer this question