How do i make it so if they click or use a keycode they can't click it at the same time get double items?

So in this game im making it so you can pick up items but idk how to make it so you can’t press a keybind and right click at the same time. When this happens the item gets duplicated and they would have 2x. How would i make this not happen? Heres the script

local UIS = game:GetService("UserInputService")
local pickupkey = "F"
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local PlayerGui = player:WaitForChild("PlayerGui")
local PickupInfoGui = PlayerGui:WaitForChild("PickupInfoGui")

UIS.InputChanged:Connect(function(input)
	if mouse.Target then
		if mouse.Target:FindFirstChild("Pickable") then
			local item = mouse.target
			
			PickupInfoGui.Adornee = item
			PickupInfoGui.ObjectName.Text = item.name
		else
			PickupInfoGui.Adornee = nil
		
		end
	end
end)
UIS.InputBegan:Connect(function(input, processed)
	if processed then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.KeyCode == Enum.KeyCode.F then
		if mouse.Target and mouse.Target:FindFirstChild("Pickable") then
			local item = mouse.Target
			if item then
				local distanceFromItem = player:DistanceFromCharacter(item.Position)
				if distanceFromItem < 30 then
					PickupItem:FireServer(item)

				end
			end
		end
	end
end)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.KeyCode == Enum.KeyCode.F then
	if input.UserInputType == Enum.UserInputType.MouseButton1 and input.KeyCode == Enum.KeyCode.F then return end

If right click and the F key are pressed, the script will not run.

1 Like

but when i press it at the same time it runs and it duplicates the item

1 Like
local allowed = true -- Don't need to change this
local blockduration = 0 -- Set to 0 if not: Choose a duration to disable for

local UIS = game:GetService("UserInputService")
local pickupkey = "F"
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local PlayerGui = player:WaitForChild("PlayerGui")
local PickupInfoGui = PlayerGui:WaitForChild("PickupInfoGui")

UIS.InputChanged:Connect(function(input)
	if allowed == true then
		allowed = false
	if mouse.Target then
		if mouse.Target:FindFirstChild("Pickable") then
			local item = mouse.target

			PickupInfoGui.Adornee = item
				PickupInfoGui.ObjectName.Text = item.name
			else
				PickupInfoGui.Adornee = nil
            end
		end
		wait(blockduration)
		allowed = true
	end
end)
UIS.InputBegan:Connect(function(input, processed)
	if allowed == true then
		allowed = false
	if processed then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.KeyCode == Enum.KeyCode.F then
		if mouse.Target and mouse.Target:FindFirstChild("Pickable") then
			local item = mouse.Target
			if item then
				local distanceFromItem = player:DistanceFromCharacter(item.Position)
				if distanceFromItem < 30 then
						PickupItem:FireServer(item)
                   end
				end
			end
		end
		wait(blockduration)
		allowed = true
	end
end)

it works when i click f first but when i click then f it doesn’t work?

It makes sure you can’t press them at same time

local allowed = true -- Don't need to change this
local blockduration = 0 -- Set to 0 if not: Choose a duration to disable for

local UIS = game:GetService("UserInputService")
local pickupkey = "F"
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local PlayerGui = player:WaitForChild("PlayerGui")
local PickupInfoGui = PlayerGui:WaitForChild("PickupInfoGui")

UIS.InputChanged:Connect(function(input)
	if allowed == true then
		allowed = false
	if mouse.Target then
		if mouse.Target:FindFirstChild("Pickable") then
			local item = mouse.target

			PickupInfoGui.Adornee = item
				PickupInfoGui.ObjectName.Text = item.name
			else
				PickupInfoGui.Adornee = nil
            end
		end
		wait(blockduration)
		allowed = true
	end
end)
UIS.InputBegan:Connect(function(input, processed)
	if allowed == true then
		allowed = false
	if processed then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.KeyCode == Enum.KeyCode.F then
		if mouse.Target and mouse.Target:FindFirstChild("Pickable") then
			local item = mouse.Target
			if item then
				local distanceFromItem = player:DistanceFromCharacter(item.Position)
				if distanceFromItem < 30 then
						PickupItem:FireServer(item)
                   end
				end
			end
		end
		wait(blockduration)
		allowed = true
	end
end)

although it works that kinda broke the script

debounce it so if the event is fired set debounce to true then wait a set amount of time set debounce back to false

sumn like this

local debounce = false

UIS.InputBegan:Connect(function(input, processed)
	if not debounce then
		if processed then return end
		if input.UserInputType == Enum.UserInputType.MouseButton1 or input.KeyCode == Enum.KeyCode.F then
			if mouse.Target and mouse.Target:FindFirstChild("Pickable") then
				debounce = true
				local item = mouse.Target
				if item then
					local distanceFromItem = player:DistanceFromCharacter(item.Position)
					if distanceFromItem < 30 then
						PickupItem:FireServer(item)
					end
				end
			end
		end
		wait(5)
		debounce = false
	end
end)

Do you read scripts, or just copy and paste. If you haven’t already, then read.

How did it break the script???

when it got adorneed it kept like glitching and the item name didn’t show

local allowed = true -- Don't need to change this
local blockduration = 0 -- Set to 0 if not: Choose a duration to disable for

local UIS = game:GetService("UserInputService")
local pickupkey = "F"
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local PlayerGui = player:WaitForChild("PlayerGui")
local PickupInfoGui = PlayerGui:WaitForChild("PickupInfoGui")

UIS.InputChanged:Connect(function(input)
	if allowed == true then
		allowed = false
	if mouse.Target then
		if mouse.Target:FindFirstChild("Pickable") then
			local item = mouse.target

			PickupInfoGui.Adornee = item
				PickupInfoGui.ObjectName.Text = item.name
			else
				PickupInfoGui.Adornee = nil
            end
		end
		wait(blockduration)
		allowed = true
	end
end)
UIS.InputBegan:Connect(function(input, processed)
	if allowed == true then
		allowed = false
	if processed then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.KeyCode == Enum.KeyCode.F then
		if mouse.Target and mouse.Target:FindFirstChild("Pickable") then
			local item = mouse.Target
			if item then
				local distanceFromItem = player:DistanceFromCharacter(item.Position)
				if distanceFromItem < 30 then
						PickupItem:FireServer(item)
                   end
				end
			end
		end
		wait(blockduration)
		allowed = true
	end
end)

edited again

Tell me if you want it to be disabled until the player leave and rejoins. Then I’ll fix to that.

it broke the entire script

this is as ive described above and there is a code example up there where ive edited it

try my code

300000 charraaccctteerrsss

Are you sure broken???
It should work.

local allowed = true -- Don't need to change this
local blockduration = 0 -- Set to 0 if not: Choose a duration to disable for

local UIS = game:GetService("UserInputService")
local pickupkey = "F"
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local PlayerGui = player:WaitForChild("PlayerGui")
local PickupInfoGui = PlayerGui:WaitForChild("PickupInfoGui")

UIS.InputChanged:Connect(function(input)
	if allowed == true then
		allowed = false
	if mouse.Target then
		if mouse.Target:FindFirstChild("Pickable") then
			local item = mouse.target

			PickupInfoGui.Adornee = item
				PickupInfoGui.ObjectName.Text = item.name
			else
				PickupInfoGui.Adornee = nil
            end
		end
		wait(blockduration)
		allowed = true
	end
end)
UIS.InputBegan:Connect(function(input, processed)
	if allowed == true then
		allowed = false
	if processed then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.KeyCode == Enum.KeyCode.F then
		if mouse.Target and mouse.Target:FindFirstChild("Pickable") then
			local item = mouse.Target
			if item then
				local distanceFromItem = player:DistanceFromCharacter(item.Position)
				if distanceFromItem < 30 then
						PickupItem:FireServer(item)
                   end
				end
			end
		end
		wait(blockduration)
		allowed = true
	end
end)

Try again

yes, it worked thanks for helping

Thanks for saying the same thing that I said too!