I'm having a problem with one of my scripts. I have it coded to where every time you pick up this chicken it should give you a point every second. I have this set up and working for kills, however when I do it with the point system it gives me an error that says, "attempt to index nil with 'leaderstatstwo' ". I don't know what the problem is. This is the script inside the chicken, where the error is occuring.
while true do
if script.Parent.Count.Value == true then
local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent)
wait(1)
plr.leaderstatstwo.ChickenLB.Value = plr.leaderstatstwo.ChickenLB.Value + 1
end
wait()
end
This is the script that spawns the folder inside the player.
game.Players.PlayerAdded:Connect(function(player)
local foldertwo = Instance.new("Folder",player)
foldertwo.Name = "leaderstatstwo"
local chickenlb = Instance.new("IntValue",foldertwo)
chickenlb.Name = "ChickenLB"
end)
Third script found inside startergui>ScreenGUI>TextLabel, this is the local script.
while wait() do
local player = game.Players.LocalPlayer
script.Parent.Text = "Chicken Points: "..player:WaitForChild("leaderstatstwo"):FindFirstChild("ChickenLB").Value
end
It even shows the folder and the IntValue whenever you play and look under the player's folder.

3 comments
EDIT: It spawns a folder inside the player. The script however is inside the workspace.
is the first code inside a normal or local script?
Normal script