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?
Im making a tool shop but im having an issue with actually buying it.
What would i do is when player clicks the buy button FireServer and send the name of the selected item info to OnServerEvent.
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
end
end
local function purchaseItem()
...
end
buyButton.Activated:Connect(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.
What is the listOfItemButtons for?
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.
listOfItemButtons is well, a list of all the item buttons, lets say
listOfItemButtons = {script.Parent.ShovelButton, script.Parent.HammerButton}
check your list, maybe its not initializing correctly
print(button.Name)
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
button.Activated:Connect(function()
if button.Text == '' and currentRolls ~= 0 then
lastScore = index
tricksEvent:FireServer("score",index)
end
end)
end
Thanks for trying. I will continue to try to make it all one script.