This is a UIS that is supposed to place a part 0,0,-5 to you. It works perfectly just that it doesn't have gps which means when players talk it will run. Which i don't want. How can i prevent this?
local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait();
local UIS = game:GetService("UserInputService")
local attacks = { -- Dictionary mapping relevant keycodes to attacks
[Enum.KeyCode.Q] = function()
local Part = Instance.new("Part")
Part.Parent = workspace
Part.CFrame = char.Head.CFrame * CFrame.new(0,0,-5)
wait(3)
end;
[Enum.KeyCode.E] = function()
local Part = Instance.new("Part")
Part.Parent = workspace
Part.CFrame = char.Head.CFrame * CFrame.new(0,0,-5)
wait(3)
end;
}
local function ForceDebounce(func) -- Forces a debounce onto the function passed in
local debounce = false;
return function(...)
if(not debounce) then
debounce = true;
func(...);
debounce = false;
end
end
end
local function ForceDebounceAllAttacks() -- Forces debounce on each function in the dictionary above
for i, v in pairs(attacks) do
attacks[i] = ForceDebounce(v);
end
end
ForceDebounceAllAttacks();
UIS.InputBegan:Connect(function(Input)
for i, v in pairs(attacks) do -- loop through attacks dictionary
if(Input.KeyCode == i) then
v(); -- Run the function associated with key
end
end
end)
