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

Does anybody know why FindFirstChild is indexing as nil?

Asked by 3 years ago
Edited 3 years ago
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
Could be the LocalPlayer hasnt finished loading in. (not 100% sure) You could try using game.Players.LocalPlayer:WaitForChild("Posting") switchflake 24 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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)
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' joshuavdm1234567 0 — 3y
0
is this in a server script? if so, was the variable created by the server or client? switchflake 24 — 3y
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 joshuavdm1234567 0 — 3y
0
It's in starterplayerscripts joshuavdm1234567 0 — 3y
0
The server cannot see the location of anything reparented or cloned by the client unless you tell the server via remote event switchflake 24 — 3y
Ad
Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago

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.

0
then the error would be "attempting to index nil with LocalPlayer" Dan_PanMan 227 — 3y
0
What do you mean.. if so then use :GetService("Players") if something renamed it.. imKirda 4491 — 3y

Answer this question