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

how do i make a gui button get pressed by a hotkey?

Asked by 5 years ago
Edited 5 years ago
Gui = Instance.new("ScreenGui", game.CoreGui)
Button = Instance.new("TextButton", Gui)
Button.Size = UDim2.new(0, 100, 0, 40)
Button.BackgroundTransparency = 0.7
Button.Position = UDim2.new(0.003, 0, 0.93, 0)
Button.Text = "Enable Noclip"
Button.TextColor3 = Color3.new(255, 255, 255)
noclip = false
game:GetService('RunService').Stepped:connect(function()
if noclip then
game.Players.LocalPlayer.Character.Humanoid:ChangeState(11)
end
end)
Button.MouseButton1Down:connect(function()
noclip = not noclip
if Button.Text == "Enable Noclip" then
    Button.Text = "Disable Noclip"
else
    Button.Text = "Enable Noclip"
end
end)

how do i make the thing this gui activates when i press the button with my cursor activate with a key?

edit:

noclip = true
game:GetService('RunService').Stepped:connect(function()
if noclip then
game.Players.LocalPlayer.Character.Humanoid:ChangeState(11)
end
end)

now the noclip is true ,how do i make it false by pressing a key? and then if i press again it will be true again, and the response i got at the other question didnt work

0
format your question: https://forum.scriptinghelpers.org/topic/82/how-to-format-questions-answers-on-the-main-site yHasteeD 1819 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago
local Gui = Instance.new("ScreenGui", game.Players.LocalPlayer.PlayerGui)

local Button = Instance.new("TextButton", Gui)
Button.Size = UDim2.new(0, 100, 0, 40)
Button.BackgroundTransparency = 0.7
Button.Position = UDim2.new(0.003, 0, 0.93, 0)
Button.Text = "Enable Noclip"
Button.TextColor3 = Color3.new(255, 255, 255)

local noclip = false

local function Activate() 
    noclip = not noclip
    if Button.Text == "Enable Noclip" then 
        Button.Text = "Disable Noclip" 
    else 
        Button.Text = "Enable Noclip" 
    end
end

local function CheckInput(Input, UIS)
    if Input.KeyCode == Enum.KeyCode.E and not UIS then
        Activate()
    end
end

Button.MouseButton1Down:Connect(Activate)
game:GetService("UserInputService").InputBegan:Connect(CheckInput)

game:GetService('RunService').Stepped:connect(function()
    if noclip then
        game.Players.LocalPlayer.Character.Humanoid:ChangeState(11)
    end
end)

I made the function standalone and connected the MouseButton1Down to it. From there, I hooked up UserInputService's InputBegan to a separate function that checks if the KeyCode is the key E. If it is, it activates the same function as the button does. https://developer.roblox.com/api-reference/event/UserInputService/InputBegan

If this helped, upvote/mark it correct! Thanks!

0
you need to explain the script. yHasteeD 1819 — 5y
0
wow this was fast TortCapsunel -5 — 5y
0
it dosent work TortCapsunel -5 — 5y
0
What errors are you getting? joritochip 705 — 5y
View all comments (5 more)
0
the noclip dosent work at all anymore TortCapsunel -5 — 5y
0
Did you hook it up to the script you already had? If you replaced your script with mine it will not work because I only put the part you asked about in my answer. What errors are you getting? joritochip 705 — 5y
0
i added it and the gui stopped working , the noclip didnt work either TortCapsunel -5 — 5y
0
Try the script now. joritochip 705 — 5y
0
it dosent activate when i press the key TortCapsunel -5 — 5y
Ad

Answer this question