Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I do an object value and the :FindfirstChild() Function with a clone?

I'll explain, This is the workspace:

workspace 
	workspace.Camera
	workspace.Terrain
	workspace.Script
	workspace.ObjectValue
		--Value = workspace.Part
	workspace.Baseplate
	workspace.Part

And this is script:

--Making the clone, setting its name to "ClonedPart", and parent to workspace.Part
Clone = workspace.Part:Clone()
Clone.Name = "ClonedPart"
Clone.Parent = workspace.Part

--Trying to set the transparency to one, but breaks
workspace.ObjectValue.Value:FindFirstChild("ClonedPart").Transparency = 1
--                          ^ turns Nil                        ^ Error

After the script

workspace 
	workspace.Camera
	workspace.Terrain
	workspace.Script
	workspace.ObjectValue
		--Value = workspace.Part
	workspace.Baseplate
	workspace.Part
		workspace.Part.ClonedPart

--Output:

Workspace.Script:5: attempt to index a nil value

How would I do this, I have throughly tested it but always ends up being nil.

1 comment

0

Your question is very confusing for me. However here's my 2 cents: a. You don't do findfirstchild to find a value. b. i think you want to store a float value, not a transparency value, because values don't have a transparency value lol

2 answers

✓ Accepted answer

Really small logic error.

Clone = workspace.Part:Clone()
Clone.Name = "ClonedPart"
Clone.Parent = workspace.Part

workspace.ObjectValue.Value:FindFirstChild("ClonedPart").Transparency = 1
--            ^ ObjectValue doesn't exist. That's why it's returning nil.

Although the class is an ObjectValue, it goes by its name, so instead, you should use the following:

workspace.Value.Value:FindFirstChild("ClonedPart").Transparency = 1
--          ^ The name of the ObjectValue

Or alternatively, you could simply rename the ObjectValue item to "ObjectValue". Either one should work.

Likewise, you could do the following if you only have one ObjectValue, or only want to find the first ObjectValue inside of Workspace. I personally don't recommend it but you do you.

workspace:FindFirstChildOfClass("ObjectValue").Transparency = 1 --Finds the first child in workspace with the ObjectValue class.

2 comments

1

Thank you!

0

No problem! Good luck with your scripting! :^)

Actually I took a different approach than using ObjectValues(findfirstchild doesent work with these), I just wanted an easy way to change the values from the workspace, but I had to seperate the values.

Workspace:
	workspace
	    workspace.Camera
	    workspace.Terrain
	    workspace.Script
	    workspace.Folder
			workspace.Folder.Layer1
				--Value: Workspace
			workspace.Folder.Layer2
				--Value: Part
			--StringValues
	    workspace.Baseplate
	    workspace.Part


Code:

--Then I put them back together, using I-pairs, and starting with Object = game
Object = game
for i,v in pairs(workspace.Folder:GetChildren()) do
	
	Object = Object:FindFirstChild(v.Value)


end

PlayerObject = Object

--This is what it is doing:
	-- the + is like using :FindFirstChild()
	--1: game + Layer1.Value
	--2: Layer1.Value + Layer2.Value

This is great because it is interchangeable, and you can still use FindFirstChild

This discussion is preserved as it was. New answers, comments, and votes are closed.