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

How Do I Retrieve Objects From An Array?

Asked by 4 years ago

So I have this script in a model, but I can't get the object back even by using something relative to its name!

Here's what I mean (My Code):

for i,v in pairs(script.Parent.ObjectStorage:GetChildren()) do
    if v.ClassName ~= 'Folder' then
        local ObjectName = Instance.new('StringValue', script.Parent)
        ObjectName.Name = v.Name
    end
end

Objects = {
    Object1 = 'River'
}

ObjectStorage = {}

function GetExistingObject()
    for i,v in pairs(script.Parent.Objects:GetChildren()) do
        if v.ClassName ~= 'Folder' then
            return v
        end
    end
end

script.Parent.Btn1.Touched:Connect(function()
    local River = GetExistingObject()
    ObjectStorage[River.Name] = RIver:Clone()
    River:Destroy()
end)

script.Parent.Btn2.Touched:Connect(function()
    local River = Objects.Object1
    ObjectStorage[River].Parent = script.Parent.ObjectStorage
end)

2 answers

Log in to vote
0
Answered by
xudet 0
4 years ago

Instead of doing :Destroy have you tried re-parenting it back into the folder so then it isn't permanently deleted from the game? That should work.

0
So, I should send the object itself into the array, then use something to get the name of that object and send it back into the game? AlphaWolf536791 28 — 4y
0
Nevermind. I just need a string that has the object's name, then I need to use that string to find the object and retrieve it! AlphaWolf536791 28 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Here's what I mean:

Object = 'Platform'
Storage = {}
Debounce = false
script.Parent.StoreGrab.Touched:Connect(function()
    if not Debounce then
    Debounce = true
        if script.Parent:FindFirstChild(Object) then
            Storage[Object] = script.Parent.Platform:Clone()
            script.Parent.Platform:Destroy()
        elseif not script.Parent:FindFirstChild(Object) then
            Storage[Object].Parent = script.Parent
        end
    wait(1.5)
    Debounce = false
end)
0
ill fix the exception AlphaWolf536791 28 — 4y
0
exception fixed AlphaWolf536791 28 — 4y

Answer this question