Attempt to index nil with 'Get Descendants'

I get the attempt to index nil with ‘GetDescendants’ Error when i’m trying to Get Descendants of object from remote event (from local script to server script)
explorerimage1

  1. What is the issue?
    I Always get error attempt to index nil with ‘GetDescendants’

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    yes, I tried looking in developer hub but i couldn’t find the solution.

Local Script (It Works Perfectly)

local Debounce = false
local Player = game.Players.LocalPlayer
local Structure = "CelestialSpawnLocation"

local RSStructures = game.ReplicatedStorage:FindFirstChild("RSStructures")

script.Parent.Activated:Connect(function()
	if Debounce == false then
	local SpaceData = Player:FindFirstChild("SpaceData")
	if SpaceData:FindFirstChild("CurrentPlanet").Value == "Outer Space" then
		
	else
		Debounce = true
		local CloneStructure = RSStructures:FindFirstChild(Structure):Clone()
		CloneStructure.Parent = game.Workspace:FindFirstChild("PreviewStructures")
		for i, Part in pairs(CloneStructure:GetDescendants()) do
			if Part:IsA("MeshPart") or Part:IsA("BasePart") or Part:IsA("UnionOperation") then
				Part.Transparency = 0.75
				Part.CanCollide = false
			end
		end
		CloneStructure:PivotTo(CFrame.new(Player.Character:WaitForChild("HumanoidRootPart").Position))
		CloneStructure:PivotTo(CFrame.new(CloneStructure:GetPivot().Position) * Player.Character:GetPivot().Rotation)
		script.Parent.Event1:FireServer(CloneStructure)
		end
	end
end)

Server Script

script.Parent.Event1.OnServerEvent:Connect(function(plr, Structure)
	for i, Part in pairs(Structure:GetDescendants()) do -- Error is at this line
		if Part:IsA("BasePart") or Part:IsA("Meshpart") or Part:IsA("UnionOperation") then
			Part.CanCollide = true
			Part.Transparency = 0
		end
	end
end)
2 Likes

The cloned structure is created on the client. Things created on the client are not accessible by the server. This results in the Structure not being sent.
You’ll have to clone it on the server, then send it to the client

but what if i want to model be only viewed by local player? (because its building system and i need to make preview model before placing)

Then you can’t be sending it to the server.
You will have to send the type of structure, plus the position and rotation, then have the server recreate what the client sees

so i can just convert local script to script?

No. You have to create the preview on the client (local script), then send just the key information to the server (normal script) , so that the server can recreate what the client sees.

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