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

UserInputService not working. No errors? [Solved]

Asked by 3 years ago
Edited 3 years ago

I tried to make a script that allowed the user to use a dash like ability but the UserInputService wouldn't detect when someone pressed a key. Can anyone Help? This is my code:

local Remote = script:WaitForChild("Remote")
local UIS = game:GetService("UserInputService")


local DB = false
local Cooldown = 10


UIS.InputBegan:Connect(function(IsTyping, Input)
    if script.Parent.Equipped == true then
        if IsTyping then return end
        if Input.KeyCode == Enum.KeyCode.X and DB == false then
            DB = true
            Remote:FireServer()
            print('Fired')
        end
    else return 
    end
end)


Remote.OnClientEvent:Connect(function()
    wait(Cooldown)
    DB = false

end)

This is what I have on the other script which detects if the remote is fired .

local Remote = script.Parent

Remote.OnServerEvent:Connect(function(player)




end)


2 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

The arguments of the InputBegan event are as follows: Instance input, bool gameProcessedEvent. There is no argument passed by InputBegan that indicate whether the client was typing. If you wish to excecute any function upon key press when client is not typing, I strongly recommend ContextActionService:BindFunction(). If you still want to use UIS, just remove the "IsTyping" argumennt you included in the event.

Ad
Log in to vote
0
Answered by 3 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

The input is the first parameter. Replace line 12

 if IsTyping.KeyCode == Enum.KeyCode.X and DB == false then
0
Your code will work, but you need to explain it for future scripters to understand. JesseSong 3916 — 3y
0
See help to learn how to format a question/answer properly: https://scriptinghelpers.org/help/how-post-good-questions-answers JesseSong 3916 — 3y

Answer this question