Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

1 answer

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!

9 comments

0

you need to explain the script.

0

wow this was fast

0

it dosent work

0

What errors are you getting?

0

the noclip dosent work at all anymore

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?

0

i added it and the gui stopped working , the noclip didnt work either

0

Try the script now.

0

it dosent activate when i press the key

This discussion is preserved as it was. New answers, comments, and votes are closed.