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

attempt to index local 'player' (a nil value)? group rank item error

Asked by 5 years ago

I get an error in my script on line 5 { attempt to index local 'player' (a nil value) } I also don't get the error in a studio test , but only in the game itself.

GroupID = 4318939
wait(2)

local player = game.Players.LocalPlayer
    -- (error here) if player:IsInGroup(GroupID) and player:GetRankInGroup(GroupID) == 255 then
        local ULTI = game:GetService("ReplicatedStorage").ULTI:GetChildren()
        for i=1, #ULTI do
            if ULTI[i]:IsA("Tool") then
                ULTI[i].Parent = player.Backpack
                local x = ULTI[i]:Clone()
                x.Parent = player.StarterGear
            end

        end
    end
1
If this is a ServerScript, you cannot use LocalPlayer in it. CPF2 406 — 5y
0
What do i use instead of LocalPlayer? ultithe 4 — 5y
0
Are you doing it when they spawn? popeeyy 493 — 5y

1 answer

Log in to vote
-1
Answered by
Voy1980 111
5 years ago
local GroupID = 4318939
wait(2)

game.Players.PlayerAdded:connect(function(player) --Don't use localplayer. It only works because when you start a test, you are the client and the server. You could do something like this ^
    if player:IsInGroup(GroupID) and player:GetRankInGroup(GroupID) == 255 then
        local ULTI = game:GetService("ReplicatedStorage").ULTI:GetChildren()
        for i=1, #ULTI do
            if ULTI[i]:IsA("Tool") then
                ULTI[i].Parent = player.Backpack
                local x = ULTI[i]:Clone()
                x.Parent = player.StarterGear
            end
        end
    end)
0
connect is deprecated, switch to Connect mate User#19524 175 — 5y
0
Alright i will try this ultithe 4 — 5y
0
Bacpack is not a valid member of Player? ultithe 4 — 5y
Ad

Answer this question