Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How am i supposed to give a gps to this UIS function?

Asked by 5 years ago

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)

1 answer

Log in to vote
1
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Add another parameter to the function connected to InputBegan, which is to be the gpe:

local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait();
local UIS = game:GetService("UserInputService")
local 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)
       local debounce = false;
       return function(...)
            if(not debounce) then
                debounce = true;
                func(...);
                debounce = false;
            end
    end
end
local function ForceDebounceAllAttacks()
    for i, v in pairs(attacks) do
        attacks[i] = ForceDebounce(v);
    end
end

ForceDebounceAllAttacks();
UIS.InputBegan:Connect(function(Input, gpe)
       for i, v in pairs(attacks) do
            if(Input.KeyCode == i) and not gpe then
                v();
            end
    end
end)

Ad

Answer this question