Can I get something from the workspace via a string?

I am trying to set up a teleport system using a single script. In each part I want you to teleport from via touch I have a stringvalue which is the part I want you to teleport to the position of. Instead, I get the error “Argument 1 missing or nil”. Here are some images of the value and my code I have so far
image
image

	local returnValue = {};

	for _, i in pairs(game:GetDescendants()) do
		pcall(function()
			if(i:GetAttribute("ID") == ID) then table.insert(returnValue, i) end; 
		end);
	end;

	return returnValue;
end;

for _, h in pairs(getInstancesWithID("Teleporter")) do
	if(h:IsA("BasePart")) then 
		h.Touched:Connect(function(hit)
			local Pos = h.Destination.Value
			hit.parent:moveTo(Pos.Position)
		end)
	end;
end;```

If you are trying to find an object through its name, use Instance:FindFirstChild(ChildName: string).
In your case however, StringValues are not even necessary, you can have a reference to your destination through an ObjectValue

e.g
ObjectValue.Value = workspace.Part
hit.Parent:MoveTo(ObjectValue.Value.Position)

1 Like

you could do something like
workspace["String here"]

1 Like