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

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

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

3 comments

1

If this is a ServerScript, you cannot use LocalPlayer in it.

0

What do i use instead of LocalPlayer?

0

Are you doing it when they spawn?

1 answer

✓ Accepted answer
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)

3 comments

0

connect is deprecated, switch to Connect mate

0

Alright i will try this

0

Bacpack is not a valid member of Player?

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