I am trying to make it so when I click the right mouse button with a tool equiped it will make a gui frame invisible and when the right mouse button isn’t clicked anymore it comes back, it just doesn’t seem to work
local gui = game.Players.LocalPlayer.PlayerGui.Crosshair:FindFirstChild("Holder")
local UserInputService = game:GetService("UserInputService")
local isRightMouseButtonDown = false
UserInputService.InputBegan:Connect(function(input, isProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
isRightMouseButtonDown = true
if gui then
gui.Visible = false
end
end
end)
UserInputService.InputEnded:Connect(function(input, isProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
isRightMouseButtonDown = false
if gui then
gui.Visible = true
end
end
end)
ive figured it out, its just now i wanna make it so when you click the right mouse button you dont have to hold it down, you can just click it and then let go
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, isProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
gui.Visible = not gui.Visible
end
end)
alright so that works issue is now the script will only work once, so how would i create a loop to check for when the button is being pressed so it makes the gui invis and vis
UserInputService.InputBegan:Connect(function(input, isProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
if gui.Visible then
gui.Visible = false
else
gui.Visible = true
end
end
end)
local gui = game.Players.LocalPlayer.PlayerGui:WaitForChild("Crosshair").Holder
local UserInputService = game:GetService("UserInputService")
local isRightMouseButtonClicked = false
UserInputService.InputBegan:Connect(function(input, isProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
if gui.Visible then
gui.Visible = false
else
gui.Visible = true
end
end
end)
local gui = game.Players.LocalPlayer.PlayerGui.Crosshair:FindFirstChild("Holder")
local UserInputService = game:GetService("UserInputService")
local connections = table.create(2)
tool.Equipped:Connect(function()
connections[1] = UserInputService.InputBegan:Connect(function(input)
if input.UserInputType ~= Enum.UserInputType.MouseButton2 then return end
gui.Visible = false
end)
connections[2] = UserInputService.InputEnded:Connect(function(input)
if input.UserInputType ~= Enum.UserInputType.MouseButton2 then return end
gui.Visible = true
end)
end)
tool.Unequipped:Connect(function()
for _, connection in connections do
connection:Disconnect()
end
end)