Attempt to index nil with 'Parent'

So i’m trying to parent a script from a replicatedstorage to a button but it says "attempt to index nil with ‘Parent’ " how can i fix this
I dont wanna do clone because it will clone a script more than once

local slotcheck = game.ReplicatedStorage.SlotCheck:Clone()
					local slot1 = game.ReplicatedStorage.SlotScripts:FindFirstChild("Slot1")
					local slot2 = game.ReplicatedStorage.SlotScripts:FindFirstChild("Slot2")
					local slot3 = game.ReplicatedStorage.SlotScripts:FindFirstChild("Slot3")
					local slot4 = game.ReplicatedStorage.SlotScripts:FindFirstChild("Slot4")
						
					UISlot.Parent = player.PlayerGui.MainMenu.Main
					UISlot.Name = "Slot"..i
					UISlot.Position = UDim2.new(0.398, 0, (0.054 + (0.170 * (i - 1))), 0)
                    
					UISlot.PlrName.Text = FirstName.." "..LastName
					UISlot.Level.Text = "Lvl. "..Level
					UISlot.Race.Text = Race
				
					if  slotcheck then
						if player:FindFirstChild("DataSlot1") and player.PlayerGui.MainMenu.Main:FindFirstChild("Slot1") then
							slotcheck.Name = 'Dataslot1'
							slot1.Parent = player.PlayerGui.MainMenu.Main:FindFirstChild("Slot1")
							slotcheck.Parent = player:FindFirstChild("DataSlot1")
						end
						if player:FindFirstChild("DataSlot2") and player.PlayerGui.MainMenu.Main:FindFirstChild("Slot2") then
							slotcheck.Name = 'Dataslot2'
							slotcheck.Parent = player:FindFirstChild("DataSlot2")
							slot2.Parent = player.PlayerGui.MainMenu.Main:FindFirstChild("Slot2")
						end
						if player:FindFirstChild("DataSlot3")and player.PlayerGui.MainMenu.Main:FindFirstChild("Slot3") then
							slotcheck.Name = 'Dataslot3'
							slotcheck.Parent = player:FindFirstChild("DataSlot3")
							slot3.Parent = player.PlayerGui.MainMenu.Main:FindFirstChild("Slot3")
						end
						if player:FindFirstChild("DataSlot4") and player.PlayerGui.MainMenu.Main:FindFirstChild("Slot4") then
							slotcheck.Name = 'Dataslot4'
							slotcheck.Parent = player:FindFirstChild("DataSlot4")
							slot4.Parent = player.PlayerGui.MainMenu.Main:FindFirstChild("Slot4")
						end

see if the object you are trying to get the parent of, exists? try printing the object and getting the result.

it exist i said i didn’t want to do cloning it clones the script more than stating it is there

are you sure it exists? did you print it to make sure?

i clearly said i didnt want to do clone it just makes more than one script under the buttons

stating it is there if i did clone

yeah, but you aren’t answering my question AT ALL. this would likely only happen if the part didn’t exist.

you fail to realize IT EXISTS IF I DID :CLONE() but WANNA DO IT A DIFFERENT WAY

you aren’t answering my question. I don’t care if it is cloned or not, check if it exists by printing it!

if the slot was found for the object to be parent why would it not be there if the script found it??? TO MOVE to the next statement under it

what line is the error on? this will help.

“slot1.Parent = player.PlayerGui.MainMenu.Main:FindFirstChild(“Slot1”)”
for some reason it annoying cause it pops up in the destinated place but errors

Is this on a server or local script?

it is a server script that is being used

I see, that’s the problem. the PlayerGui can’t be accessed through a server script, only through a local script.

how can i parent it from a server script?

i found a better way nvm and thanks for the help

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.