Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Does anybody know why FindFirstChild is indexing as nil?

Asked by 14 days ago
Edited 14 days 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 — 14d

2 answers

Log in to vote
0
Answered by 14 days 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 — 14d
0
is this in a server script? if so, was the variable created by the server or client? switchflake 24 — 14d
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 — 14d
0
It's in starterplayerscripts joshuavdm1234567 0 — 14d
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 — 13d
Ad
Log in to vote
0
Answered by
imKirda 731 Moderation Voter
14 days 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 194 — 14d
0
What do you mean.. if so then use :GetService("Players") if something renamed it.. imKirda 731 — 14d

Answer this question