Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How does UserInputService work? (I tried)

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

✓ Accepted answer

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)

1 comment

0

Oh.. XD Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.