How would i store a directory in a value?

i’m making a tower defense game, and i’m working on the tower gui upgrade system, the way it works is when the hitbox is clicked, the frame inside the tower is cloned and parented inside playergui, and close just deletes itself, now i want the gui to change the towers look and stats, but i don’t know how to store directories, i know this isn’t really “scripting”, but this was the only category i could find.

By directories do you just mean the child path to a specific instance?

yeah, that’s what i meant.

30 ch ars

If everything is in one place, you could store the parent folder/instance. What kind of flexibility do you need here?

You can try using Part:GetFullName() and put that path into your ValueBase.

So you can retrieve the path of any instance via the :GetFullName() method.
To code something like this it would be similar to this:

local Object = -- Put object here
local Path = Object:GetFullName()

Now this would return something along the lines of:
workspace.Model.Part.Decal
Obviously this is just an example, so yours will be different. But the point is, it gets the path to the instance.

Now reading that path is different. I am going to write a function that will read the path and locate the instance.

local function followPath(path)
	local steps = string.split(path,".")
	local result = game
	
	for i = 1, #steps do
		result = result[steps[i]]
		
		if result == nil then
			return nil
		end
	end
	
	return result
end

To summarize: You obtain the path with :GetFullName(), and read the path with the above function.
Hope this helps! Good luck.

  • Galactiq
1 Like

You would use an ObjectValue for this. Here’s an example of how it might work in your game.

When creating the GUI add an ObjectValue to it, to reference the tower:

local gui = ...
local tower = ...
local reference = Instance.new("ObjectValue", gui)
reference.Value = tower
reference.Name = "TowerRef"

When you want to get the tower object:

local gui = ...
local tower = gui.TowerRef.Value
1 Like

i did not know about ObjectValue, thanks!

1 Like