I'm a scripting newbie and I'm trying to make a button that when you click it disappears I have a local script as the child of a text button, this is the code I'm using.
local button = script.Parent
local function onButtonActivated()
print("Button activated!")
game.StarterGui.ScreenGui.TextButton.Transparency = 1
end
How do I make it so that the computer does the function when the button is clicked?
Check out the docs for TextButtons.
You simply need to connect your code to the Activated signal of the button.
button.Activated:Connect(onButtonActivated)
On a separate note, there's an issue with your function as well. You are modifying the button template that is in StarterGui, not the one that the player sees. UI elements are copied from StarterGui into each player's PlayerGui when the Player spawns.
To access the actual button you are trying to turn invisible, you can use relative paths, like how you defined the button variable, or give the full path to the button.
local button = script.Parent
local function onButtonActivated()
button.Transparency = 1
-- or
local player = game.Players.LocalPlayer
local btn = player.PlayerGui.ScreenGui.TextButton
btn.Transparency = 1
end
button.Activated:Connect(onButtonActivated)
There are a few ways to check if a button is clicked.
The main way is UIButton.Activated. It works the exact same as MouseButton1Click.
Something around the lines of:
button.Activated:Connect(onButtonActivated);
If this helped, you should accept either my answer or Kylaaa's answer.
try this
first make all the onButtonActivated
then instead of transperency use:
button.Visible = false
it works for me
Related
I can not understand how to change the image when you press the button
To change an image label's image you must first have the explorer tab open in roblox, to do this look at the top bar on your roblox game editor. Go into view and select explorer on the left of the top bar.
Now do as I do.
Add a screenGUI into the starterGUI folder
Into the screenGUI add a frame
And into the frame add the following items
a LocalScript
a TextButton
and a ImageLabel
Inside the localscript put this script
local label = script.Parent.ImageLabel
local frame = script.Parent
frame.TextButton.MouseButton1Click:Connect(function(click)
label.Image = "rbxassetid://284402785" --change this to whatever image you want but keep the quotation marks
end)
You can change the normal asset in the image label to whatever you want.
I have the following code that I am not able to test very well due to the testing window being so short. It is for an iPhone autotouch script that will scan a coordinate for a color and tap when the color changes to black. I added a second component to the script which functions similarly, it detects a color on the screen then taps on a specified coordinate. Is the code formatted in a way where when the first color is detected and the tap occurs, the code advances to the second portion of the code?
colorone is the variable for the first page, and colortwo is the variable for the second page (the page displayed after the first colorone button is tapped).
Thank you in advance
local colorone = getColor(165, 1566)
local colortwo = getColor(652, 2301)
repeat
colortwo = getColor(652, 2301)
until( colortwo == 0 )
tap(652, 2301);
repeat
colorone = getColor(165, 1566)
until( colorone == 0 )
tap(920, 1688);
So I have a simple text button inside of a ScreenGui with the following lua code.
local Button = script.Parent
local Frame = script.Parent.Parent.Frame
function onClick()
if Frame.Visible == false then
Frame.Visible = true
elseif Frame.Visible == true then
Frame.Visible = false
end
end
Button.MouseButton1Click:Connect(onClick)
However, when I click on the button, the frame does not show up.
The frame is set to not be visible by default.
The button is set to active, visible and selectable.
Try with a clean script changing the Frame to visible. To check if your syntax is correct. I.e.:
local Frame = script.Parent.Parent.Frame
Frame.Visible = true
If it still doesn't work, try removing the elseif. I've had issues with scripts before just not liking the elseif command. You can just put else and it will do exactly the same job.
If you add in print("Testing") right after the function starts:
function onClick()
print("Testing")
if Frame.Visible == false then
and then run the code to make sure your onClick() function is actually being called.
If the code it called it'll print "Testing" and if it doesn't print then you know your code was just never run.
I'm a bit stupid. Upon posting this question, I attempted to do some more reaserach. I found out that it might be the type of script causing it, and it was. You need to use a localscript for things like these.
Thanks anyways!
Just as a note, when you're doing logic like:
if button.Visible == true then button.Visible = false
You can simplify the code by writing
button.Visible = not button.Visible
I would answer the rest of the question, but you've already accepted one!
So I've been struggling making a button that on pressed goes to a link and toggles Enabled to false so you cant click it anymore
function CEButton1Click(sender)
shellExecute("https://google.com/search")
CEButton1.Enabled=false
end
The above is what I have so far but it does not seem to be working.
The documentation for cheat engine is severely lacking, but sender in that function is actually the button itself. This means you can simple do
sender.Enabled = false
and that successfully disables the button.
I'm writing a small pyqt program. I want the main window to to react to arrow movement. I added an event to my MainGui class, keyPressEvent, that handle this. The event work fine as long as I don't press certain buttons such as Key_Up or Key_Down are directed to my (currently only) QComboBox and not to my mainGui. I tried to give the focus to mainGui after each paintEvent but then I need to double click on buttons/comboBox.
Then I tried to use the MousePressEvent to check if a certain element is under the mouse. This work fine with the comboBox, but not with the button.
So, how can I direct key events to the mainGui or give the focus to QButtons?
I used eventFilter to identify when the mouse enter the QPushButton and give it focus:
def eventFilter(self,source,event):
if event.type() == QtCore.QEvent.HoverMove:
if self.execButton.underMouse():
self.execButton.setFocus()
self.keepFocus=False
else :
self.keepFocus=True
keepFocus is a flag I initialized in the __init__ function of the class. I added this part at the paintEvent function
if self.keepFocus:
self.setFocus()
else:
self.keepFocus = True
Now, I keep the focus at the MainGui and I only give it to the button when the mouse hove over it. If I do another action (like pressing a mouse button or a keyboard key) the focus is given back to the MainGui. This will create some buggy filling (For example, I need to press twice a keyboard key before the first response) but this is workable.