This is a support category for asking questions about how to get something done on the Roblox websites or how to do something on Roblox applications such as Roblox Studio.
You can write your topic however you want, but you need to answer these questions:
1.
Im making a project for fun and it involves stages being randomly generated every time. Some stages include objects that run on every players individual client.
When using a remote event to try to clone the client objects to the client, it says- " attempt to index nil with âCloneâ"
I tried to print debug and the object used to identify the client sided object is there but when printing the parent it returns nil. The parent looks like it exists
Here is the script for the stage generator i made:
Server Script:
local function addFloor(floor)
local randomStage = nil
if floor == nil then
randomStage = math.random(1, #storedstages)
end
if floor ~= nil then
randomStage = floor
end
local clonedStage = storedstages[randomStage]:Clone()
clonedStage.Parent = game.Workspace.Stages
table.insert(Stages,clonedStage)
local posi= Vector3.new(Base.PrimaryPart.Position.X,(Base.PrimaryPart.Position.Y+height),Base.PrimaryPart.Position.Z)
local rotfactor = #Stages+1
local rotation = (game.Workspace.Base.PrimaryPart.Orientation.Y)+(180*rotfactor)
clonedStage:SetPrimaryPartCFrame(CFrame.new(posi) * CFrame.fromEulerAnglesXYZ(0, math.rad(rotation), 0))
--clonedStage:SetPrimaryPartCFrame()
--clonedStage:MoveTo(Base.PrimaryPart.Position)
local newHeight = clonedStage:FindFirstChild("Walls"):GetExtentsSize().Y+height
height = newHeight
for i,v in pairs(clonedStage:GetDescendants()) do
game.ReplicatedStorage.RestartCos:FireAllClients(v)
end
end
local function createTower(floorcount)
height = Base:GetExtentsSize().Y
print(Stages)
--clear old stages
for i,v in pairs(Stages)do
v:Destroy()
Stages[i]=nil
end
print(Stages)
local count = nil
if floorcount == nil then
count = math.random(5,6)
else
count = floorcount
end
for i = 1,count,1 do
addFloor()
print(Stages[#Stages]:GetDescendants())
end
end
local function startTimer()
print("starting timer")
local startTime = game:GetService("ServerStorage"):WaitForChild("GameSettings"):FindFirstChild("Timer").Value
for i = startTime,0,-1 do
currentTime.Value = i
wait(1)
end
end
local function newRound()
createTower()
--startTimer()
for i,v in pairs(workspace.Stages:GetDescendants()) do
game:GetService("ReplicatedStorage").RestartCos:FireAllClients(v)
print(v.Parent)
end
print("g")
if currentTime.Value == -1 then
newRound()
end
end
Local Script (this script portion originates from an obstacle course kit):
local addPart = function(v)
if v.Name == "ClientObject" then
print(v)
local c = v.Parent:Clone()
c.Parent = v.Parent.Parent
v.Parent:Destroy()
addChildren(v,c)
ApplyPart(c)
for j,w in pairs(c:GetDescendants()) do
ApplyPart(w)
end
end
end
This portion of the script attempts to clone any of the objects to the client.
The function ApplyPart()
requires a module script inside of the parent of the part used to identify the client sided object