Attempted to index nil with parent [Solved]

local Item = game.ReplicatedStorage["Double Chocolate Cookie"] 

script.Parent.Triggered:Connect(function(player)
	print("Clicked!")
	local ItemClone = Item:Clone()
	ItemClone.Parent = player.Backpack
end)

Nothing seems to be wrong with this script. It works perfectly fine in a different game I have, when I check the game in server mode whilst testing, the items are still there.

What’s wrong here?

Error:
Workspace.Model.Lemon.ProximityPrompt.GiveScript:6: attempt to index nil with ‘Parent’

try changing

local Item = game.ReplicatedStorage["Double Chocolate Cookie"] 

to

local Item = game.ReplicatedStorage:WaitForChild("Double Chocolate Cookie")

as the item might not be loaded before the script is loaded

2 Likes
local Item = game:GetService("ReplicatedStorage"):WaitForChild("Double Chocolate Cookie")

script.Parent.Triggered:Connect(function(player)
	print("Clicked!")
	local ItemClone = Item:Clone()
	ItemClone.Parent = player:WaitForChild("Backpack")
end)

its better to use waitforchild, this to make sure the script isnt running its code before the item even exists in game.

this shouldn’t return nil, if it does the name in the script doesnt match the actual item name.

It still returned nil even though it perfectly matches the name.

hold on im gonna test it in studio as well

That’s the thing, I tried that and it worked, but I try it in my main game it didn’t.

it seems to work for me, did you check the capitals too? copy the exact name of the item and then paste it in the quotes

Already have, it is character for character.

thats very weird, with main game you mean play it via the roblox launcher?

No, in studio testing, not the roblox launcher.

I have two separate studios running right now, one to test, one to add to the game. The game one isn’t working.

okay, well then its not a problem with the saving to roblox.

uhm can you copy and paste the whole error from the output window?

  20:11:39.007  Stack Begin  -  Studio
  20:11:39.007  Script 'Workspace.Model.Lemon.ProximityPrompt.GiveScript', Line 6  -  Studio - GiveScript:6
  20:11:39.007  Stack End  -  Studio```

it doesnt say what the error is?

just stack begin/end.

did you change player.backpack to player:WaitForChild(“backpack”) aswell?

I’ll try that.

Here’s the whole error, sorry, the first part didn’t copy:

  20:17:07.813  Workspace.Model.Lemon.ProximityPrompt.GiveScript:6: attempt to index nil with 'Parent'  -  Server - GiveScript:6
  20:17:07.813  Stack Begin  -  Studio
  20:17:07.813  Script 'Workspace.Model.Lemon.ProximityPrompt.GiveScript', Line 6  -  Studio - GiveScript:6
  20:17:07.813  Stack End  -  Studio

any change you are in team create in one of the studio’s and the script isnt commited yet?

so it say the item you want to parent to the players backpack is nil, try printing the model

just do

warn(ItemClone)

It returned “nil” even though the server AND the client both see it in replicated storage.

Script doesn’t find tool in backpack
Similar post ^^^
Check it out : Their solution - I moved the script from StarterPlayerScripts to StarterGui and it is now working…
Also make sure the object was made in a server script because if it is on client the server won’t find it.

Archivable is activated? must be true if the object can be cloned.

1 Like