Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
Nootian 184
4 years ago
Edited 4 years ago

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.

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 Cyroxite 46 — 4y

2 answers

Log in to vote
0
Answered by
7z99 203 Moderation Voter
4 years ago
Edited 4 years ago

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.
1
Thank you! Nootian 184 — 4y
0
No problem! Good luck with your scripting! :^) 7z99 203 — 4y
Ad
Log in to vote
0
Answered by
Nootian 184
4 years ago
Edited 4 years ago

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

Answer this question