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

Does anybody know why FindFirstChild is indexing as nil?

local PoBox = game.Workspace.Assets.PostBox31
local Posting = game.Players.LocalPlayer:FindFirstChild("Posting")
Posting.Value = false

PoBox.ClickDetector.MouseClick:Connect(function(clicked)
	if Posting.Value == true then
		game.ReplicatedStorage.AlreadyPosting:FireClient()
		print("Already posted fired")
	else
		game.ReplicatedStorage.PostingStarted:FireClient()
		print("Fired")
	end
end)

Output:
17:07:25.565 - Workspace.Assets.PostBox31.PostingScript:2: attempt to index nil with 'FindFirstChild' 17:07:25.566 - Stack Begin 17:07:25.566 - Script 'Workspace.Assets.PostBox31.PostingScript', Line 2 17:07:25.567 - Stack End

Using WaitForChild shows the error: 17:18:35.169 - Workspace.Assets.PostBox31.PostingScript:2: attempt to index nil with 'WaitForChild'

1 comment

1

Could be the LocalPlayer hasnt finished loading in. (not 100% sure) You could try using game.Players.LocalPlayer:WaitForChild("Posting")

2 answers

Also if that doesnt help then you can also define posting in the mouseclick function

local PoBox = game.Workspace.Assets.PostBox31

PoBox.ClickDetector.MouseClick:Connect(function(clicked)
local Posting = game.Players.LocalPlayer.Posting
Posting.Value == not Posting.Value 
  if Posting.Value == true then
        game.ReplicatedStorage.AlreadyPosting:FireClient()
        print("Already posted fired")
    else
        game.ReplicatedStorage.PostingStarted:FireClient()
        print("Fired")
    end
end)

5 comments

0

@switchflake with your code after i click it it says 17:24:28.868 - Workspace.Assets.PostBox31.PostingScript:4: attempt to index nil with 'Posting'

0

is this in a server script? if so, was the variable created by the server or client?

0

@switchflake this is a server script. The variable "Posting" is a BoolValue in replicatedStorage. There is a localscript which clones the BoolValue names it "Posting" and parents it to the player

0

It's in starterplayerscripts

0

The server cannot see the location of anything reparented or cloned by the client unless you tell the server via remote event

It is probably because you are not doing it in a local script, so that is why the player is nil, you can access local player with Local Script only.

2 comments

0

then the error would be "attempting to index nil with LocalPlayer"

0

What do you mean.. if so then use :GetService("Players") if something renamed it..

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