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

"Reference" the location of an object?

Asked by 10 years ago

I'm making a game where you can place buildings. When you click on the building, it copies its GUI into PlayerGui and opens up a window with buttons. One of these buttons should be able to delete the building... however, I don't know how to "reference" back to the building!

If I do script.Parent it'll just spit out "PlayerGui". So... is there any way to store the location of the building model when the GUI is created, then use it to delete the model at a later time?

P.S. I know this is a bit... well, a lot... confusing. Let me know in the comments if there's something you guys don't understand

Thanks, Nikola7007

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

A good way to do this is to 'tag' the building using an ObjectValue.

For example, when you're cloning the gui into the player's playergui then put an objectvalue in the gui with a value of the building..

local gui = game.ServerStorage:FindFirstChild('HypotheticalGui')

if gui then
    local newGui = gui:Clone()
    newGui.Parent = Player.PlayerGui
    --Tag it--
    local obj = Instance.new('ObjectValue',newGui)
    obj.Name = 'HouseReference'
    obj.Value = House
    ----------
end
0
ObjectValue sounds perfect! Can't believe I didn't notice that... I'll try it out. Thanks! Nikola7007 25 — 10y
0
It works! Nikola7007 25 — 10y
0
Sweet(: Goulstem 8144 — 10y
Ad

Answer this question