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

How Do I Retrieve Objects From An Array?

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

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.

2 comments

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?

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!

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)

3 comments

0

ill fix the exception

0

exception fixed

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