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

How does UserInputService work? (I tried)

Asked by
asgm 109
4 years ago

So.., I did this after 3 hours failing to do Mouse.Button1Down and Button1Up. I thought it would solve my problem ...

UserInputService = game:GetService("UserInputService")
ChargeTime = script.Parent.Configurations.ArrowCharge.Value
FireEvent = game:GetService("ReplicatedStorage").BowEvents.FireEvent

local ReloadTime = script.Parent.Configurations.ArrowReload.Value
local mouse = game.Players:GetPlayerFromCharacter(script.Parent.Parent):GetMouse()
local charge = 0
reloading = false
holdDown = script.Parent.holdDown.Value

local function Press()
    while UserInputService:IsMouseButtonPressed() == true do
        print("hold")
        wait(0.1)
    end
    if UserInputService:IsMouseButtonPressed() == false then
        print("FIRED")
    end
end

if UserInputService.InputBegan == Enum.KeyCode.ButtonL1 then
    print("click")
    Press()
end

It's a charging script for a bow. (It's a local script) What's the problem or is there any workaround?

1 answer

Log in to vote
1
Answered by
Gojinhan 353 Moderation Voter
4 years ago
Edited 4 years ago

yikes. The effort was nice but you REALLY should have looked on the wiki or explored the syntax.

here's a template for how you'd use input service with a mouse sorta thing.

local uis = game:GetService("UserInputService")

uis.InputBegan:connect(function(input, gp)
if gp then
    return

    else
        if input.UserInputType == Enum.UserInputType.MouseButton1 then
            -- start charging
        end
    end 
end

end)

uis.InputEnded:connect(function(input) -- optional, turn it into a comment with -- if you dont want this.
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        --stop charging then fire
    end
end)
0
Oh.. XD Thanks! asgm 109 — 4y
Ad

Answer this question