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
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!