Ok I put this script inside of a frame that has TextButtons for children, but I also have a LocalScript inside of the frame directly below the script and I want the LocalScript to Activate after the player has chosen classes, what's wrong with this?
player = script.Parent.Parent.Parent backpack = player.Backpack function chooseClass(class) for i, v in pairs(backpack:GetChildren()) do v:remove() end for i, v in pairs(class:GetChildren()) do if v:IsA("Tool") then v:clone().Parent = backpack elseif v:IsA("HopperBin") then v:clone().Parent = backpack end end script.Parent.Main.Visible = false script.Parent.Title.Visible = false end function onHumanoidDied(humanoid, player) script.Parent.Main.Visible = true script.Parent.Title.Visible = true end for i, v in pairs(script.Parent.Main:GetChildren()) do v.MouseButton1Up:connect(function () chooseClass(v) end) end game.StarterGui.Class.Main.LocalScript.Disabled = true function LocalScript() if LocalScript.Disabled == true then game.StarterGui.Class.Main.TextButton.MouseButton1Clicked:wait() game.StarterGui.Class.Main.LocalScript.Disabled = false end end LocalScript.TextButton.MouseButton1Clicked:connect()
The problem is two-fold.
First of all, if that is all of your code, that function never runs because it is never called.
Second, onClicked
is not a valid member of anything, really.
Since you only want this code to run once (I assume), try using the wait
method of MouseButton1Clicked
, which is a member of TextButton
:
game.StarterGui.Class.Main.LocalScript.Disabled = true game.StarterGui.Class.Main.TextButton.MouseButton1Clicked:wait() game.StarterGui.Class.Main.LocalScript.Disabled = false
Lastly, and this is just a readability thing, your placement of then
is weird.
The 'standard' is to type it like this:
if condition then --[[code]] end --or if condition then --[[code]] end
Instead of:
if condition then --[[code]] end
This makes it easier to read the statement, especially if there are multiple 'code' lines being run, and it also makes it blatantly obvious when an if-statements checks are continued on the next line, which isn't the case in your code.