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

When i click this button it says it cant be found?

Asked by 6 years ago

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)

1 answer

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Before you do the click event you should make an if statement with :IsA() to check that the current buttons in the for loop is a TextButton or whatever so that the MouseButton1Click event is part of the instance. also theres no point in the button in (function(button) because it'll just be nil anyways.

Comment edit

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
  if buttons:IsA("TextButton") then
    buttons.MouseButton1Click:connect(function()
        print("A button was clicked")

        end--]]
    end)
  end
end
0
Then how do i do it with only one script in a simple way? KinqAustinn 293 — 6y
0
Then how do i do it with only one script in a simple way? KinqAustinn 293 — 6y
0
@EndorsedScripter ;-;.. edited answer DanzLua 2879 — 6y
0
oh okay, ill try it KinqAustinn 293 — 6y
View all comments (10 more)
0
Okay, how do i detect which button was click? KinqAustinn 293 — 6y
0
@EndorsedScripter You could check it's name in an if statement. buttons.Name DanzLua 2879 — 6y
0
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 KinqAustinn 293 — 6y
0
way KinqAustinn 293 — 6y
0
i ment way not name KinqAustinn 293 — 6y
1
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 DanzLua 2879 — 6y
0
@EndorsedScripter DanzLua 2879 — 6y
0
Okay ill try that KinqAustinn 293 — 6y
0
Also, the MouseButton1Click event does not have a parameter dpark19285 375 — 6y
0
Alright it worked thanks :D KinqAustinn 293 — 6y
Ad

Answer this question