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)
-
What is the issue?
I Always get error attempt to index nil with ‘GetDescendants’
-
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)