Help making a tool shop

Im making a tool shop but im having an issue with actually buying it.

when you click the item the info comes up and the buy button but I cant figure out how to tell the buy button what it is to give to the player. how could I do this?

What would i do is when player clicks the buy button FireServer and send the name of the selected item info to OnServerEvent.

1 Like

Are you putting the logic for these two operations in different scripts?

If not I would do something to this effect.

local selectedItem = nil
local listOfItemButtons = {}

-- selection button setup
for _, button in pairs(listOfItemButtons) do
   button.Activated:Connect(function()  -- setting up the connection here lets it know which button it is
      selectedItem = button.Text -- or however you differentiate them

local function purchaseItem()


This way the script knows which item has its data shown at any time, with the buy button in the same scope, it too knows that info.

1 Like

What is the listOfItemButtons for?

This video by AlvinBlox might be of help.

1 Like

I think I get it now ill do it this way

Just a way to only type the function once.
It is a table with all your item buttons in it.
So the picture would be { M16 button, Lockpick button }

You can pull in the children from the frame they are in so when you add a new item and therefore button, you don’t need to go back in and change the script.

1 Like

listOfItemButtons is well, a list of all the item buttons, lets say
listOfItemButtons = {script.Parent.ShovelButton, script.Parent.HammerButton}

1 Like

Im doing it this way but I cant get it to work. It wont print selected item.

check your list, maybe its not initializing correctly
before the connection.

I do that and It prints all the buttons without me clicking them

I’m at a loss. This is a snippet from one of mine, that looks the same.

for index, button in pairs(scoreButtons) do
		if button.Text == '' and currentRolls ~= 0 then
			lastScore = index
1 Like

Thanks for trying. I will continue to try to make it all one script.