Local player index nil

heya everyone, got a small issue with my local player which seems to be returning as nil for some reason… little help?

Players = game:GetService("Players")

local boards = workspace:WaitForChild('Boards')

local screen = boards.Screen

while task.wait(0) do

	local sgui = screen:WaitForChild("SurfaceGui").MainFrame.ScrollingFrame
	local frame = sgui:WaitForChild("Frame")

	for i, player in pairs(Players:GetPlayers()) do

		playerlist = player.Name

	end

	name = frame.Title.Text
	number = frame.Number.Text

	if number == '1.' and name == playerlist then
		
		local ss = game:GetService("ServerStorage")
	
		local fCyokai = nil

		fCyokai = ss.Floaties.Bundles.Angel:WaitForChild("Head"):Clone()
		
		local plr = game.Players.LocalPlayer
		local character = plr.Character or plr.CharacterAdded:wait()

		local hum = character:WaitForChild("Head")

		local ry = fCyokai:WaitForChild("RootPart")

		fCyokai.Parent = hum

		ry.Parent = hum	

		ry.Animate.Part0 = hum

		ry.Animate.Part1 = ry

		ry.Animate.Parent = hum			

	end

end

2 Likes

You cant access the LocalPlayer on a server script. It will return nil, which is why you are getting that error.

2 Likes

Are you sure you’re doing this on a LocalScript?

2 Likes

how can I grab the character then

2 Likes

forgot to say that it was a server script.

1 Like

Change it to a LocalScript then lol

This also works well for changing UI aspects as you’re handling it from the client side

If you detect the Local Player from the Server Side, it will automatically return back nil because where is the Server supposed to exactly detect the Player? It can’t because those are mainly used for handling server-sided Events

2 Likes

understood, im gonna try doing something else anyways so I might not even use the server script at all I was just really confused of why I was getting a nil value back

1 Like