So im making a tycoon kit that uses a gui and when i click a button i want it to detect when its clicked and i want to do it in one script, but it dont work please help! heres the script
local Player = game.Players.LocalPlayer
local Tycoon
local Ls = Player.leaderstats
local Cash = Ls.Cash
for _,buttons in pairs(script.Parent.Background.Buttons:GetChildren())do
buttons.MouseButton1Click:connect(function(button)
print("A button was clicked")
--[[if buttons.Bought.Value == false then
if Cash.Value >= buttons.Cost.Value then
local Tycoon = game.Workspace.TycoonKit:FindFirstChild(Player.Owned_Tycoon.Value)
if Tycoon then
local Item = Tycoon.Buyables:FindFirstChild(buttons.Item.Value)
if Item then
Item.Parent = Tycoon.Bought
Cash.Value = Cash.Value - buttons.Cost.Value
end
end
end
end--]]
end)
end
But thats the part thats not working
buttons.MouseButton1Click:connect(function(button)

14 comments
Then how do i do it with only one script in a simple way?
Then how do i do it with only one script in a simple way?
@EndorsedScripter ;-;.. edited answer
oh okay, ill try it
Okay, how do i detect which button was click?
@EndorsedScripter You could check it's name in an if statement. buttons.Name
is there a easier name that can just get the info of it in the button without having to do a bunch of if statments
way
i ment way not name
uh whats the problem, if theres something inside that textbutton you want you could just do buttons.thingyouwant and make sure its there stuff like that
@EndorsedScripter
Okay ill try that
Also, the MouseButton1Click event does not have a parameter
Alright it worked thanks :D