Code working on Models Taken out of lighting cant detect part in Model

So Basically ive been seeing an error message pop up in my Output when I clone a model from lighting and place it in Workspace, saying

"Part is not valid member of Model"

the error happens in a RenderStepped function and the error message happens almost as soon as the model is parented to workspace. Which makes me think maybe it hasn’t loaded in as quick as the model has if that makes sense? So I put a Model:WaitForChild(“Part”) instead of Model.Part. But then in InfiniteYield Possible message comes up.

So now im really confused because i check the explorer and the Model does have a Part inside it (ClientSide and ServerSide so its definatly there) but the code keeps breaking because its not detecting the Part inside the Model.

This is some example code from the game showing parts of code from a client and server script

---Everythings just named for simplicitys sake

-- There is a model in lighting called Model which include one part called "Part"
-- There is a Folder in Workspace called Folder
-- There is a Folder Called RemoteEvents that includes 2 Remoted events called, "CloneModelFromLighting" and "RemoveModelFromFolder"
-- Server script located in Workspace
-- Client Script located in StarterPlayerScripts

--Client 

game:GetService("RunService").RenderStepped:connect(function() -- This function just fires repeatedly as quick as possible 
	
	local Models = game.Workspace.Folder:GetChildren()

	for i = 1,#Models do
		print(Models[i]:WaitForChild("Part").Name) -- The problem is it cant detect the Part EVEN THOUGH ITS THERE
	end
	
end)

--Server
--this is just here to show that the folder is Removing and adding models throught the game

game.ReplicatedStorage.RemoteEvents.CloneModelFromLighting.OnServerEvent:Connect(function()
	game.Lighting.Model:clone().Parent = game.Workspace.Folder
end)

game.ReplicatedStorage.RemoteEvents.RemoveModelFromFolder.OnServerEvent:Connect(function(Model) -- Model is a Model that Client wants to remove from folder
	Model:Destroy()
end)

This problem isnt just for this client script.
its also a problem for just server scripts so its not an FE problem

So my question is why am I having problems detecting a Part if its definitely there?

Thanks for reading ~ Anon

(Sorry if this is a really obvious mistake)

For cloning purposes like mentioned above: I would take things from ReplicatedStorage instead. As a question, why Lighting? (I’m not sure if this would fix it, or if it’s something im missing)

1 Like

That’s the first thing I thought. but I’ve been using lighting to store for so long now its just a bad habit.

I learned from using a lot of premade codes from toolbox and a lot of them used lighting to store.

It would take days to have everything taken from ReplicatedStorage so unless its definitely a lighting problem id rather not change it lol

But if its a lighting problem why is it a lighting problem. Is it Not loading the parts inside the model quick enough to workspace? if that’s the case then surely the Infinite Yield Possible message wouldn’t display?

Like I said; I don’t know if it really is a Lighting problem.
I’ve only used lighting for about one thing, individual part cloning, for humanoid effects similar to infection style things.
May i ask why you are making a table of Model instances and searching each for the part? Maybe just have something send the literal instance to the client, and then RenderStepped just reading that model?

Its quite hard to explain.
Ive created a camera system of like a 2d kind of style which you can drag and zoom into things

if you really wanna see its for this game im working on here: ☢️####[########ph####]####R####b########x####Sh### - Roblox

And basically the rendered step function is looking too see which model the camera is closest too and firing an event for the server to update if the closest model has been changed.

but when a new room has been added to the folder. the rendered step function breaks like 1-3 times but works after that? its kind of weird.

so i cant just send the literal instance to the client because the camera is client based so only the client knows what the closest model is to send to the server. but its not detecting the Primary part inside the model that it can measure the magnitude from :confused:

Ah. I see. You want the camera to fly to the model that was created by the player, correct?

May i see heraldry of the object?

The code that breaks is actually too see which room needs to have UI activated in them.

Because it looks better to have the UI only visible in the rooms that the player is zoomed into

Do you still need the structure?

Yeah, it’d probably help. As for the UI you’re talking about, do you mean like internal screens or something?

What you could to is fire a BindableEvent to the sever to return the CFrame of the part, then create one there on the client. Wouldn’t solve the problem, but instead go around it.

I have NPCs that have Billboard UIs that activate if the room there in is zoomed in to0.

Also what’s a Heraldry, your going to have to explain that word chief :slight_smile:

I have this problem with multiple Scripts so I don’t want to make a mess with blindable events…

I’m kind of hoping that there’s a solution that will fix it and i don’t have to worry about it if I have to reference it again in the future. cause I keep a lot off different models in the lighting space that it might happen too as well.

Thanks for the suggestion though means a lot. I really need the help cause I have no clue at this point

I think he means “hierarchy”, or (in other words) your explorer widget.
When this happens, I put print(<error.Parent>:GetChildren(), <error.Parent>.Name) to see where this is going wrong.

Bit late tho sorry, I was eating lunch.

Yeah, haha i used the wrong word

1 Like

Its a bit of a mess so I simplified it down to everything the scripts touch and made the names more simple

image

It should be the exact layout I referenced in the comment section of the Lua segment in the Main

I think its because Lighting may (?) not be able to store BaseParts, because thats why it says Can't find Part, not Cant Find Model. I know that putting 2 skyboxes automatically deletes the other, maybe this is the same problem? You could check if the part is still there ingame. If not, try putting it in the repStorage.
You can use the Find All/Replace All tool to simplify the process, if needed.

That’s about all i can think of why it won’t work anymore.

1 Like

Expand Model in that screenshot

When I test it in studio the Part is defo there, Client Side and Server Side.

(Edit) because its quite an uncommon bug im going to wait until i have spare time after working and ill try to convert everything from lighting to ReplicatedStorage. Ill let you all know how it goes.

Anyone reading this thread know anything else to try please let me know

Thanks for all the help lads

Sorry didn’t notice