I’m making a melee weapon and I only want the player to be able to attack when they’re holding right click.
I tried using UserInputService but it doesn’t work.
local UIS = game:GetService("UserInputService")
ready = false
UIS.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
ready = true
print("ready TRUE")
end
end)
UIS.InputEnded:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
ready = false
print("ready TRUE")
end
end)
function on(t)
local h = t.Parent:FindFirstChildOfClass("Humanoid")
if h ~= nil and CanDmg == true and ready == true then
CanDmg = false
local cre = Creator.Value
h:TakeDamage(parent.Dmg.Value)
Handle.Swing:Stop()
Handle.Hit:Play()
if h.Health>0 then
if not h:FindFirstChild("creator") then
local ov = Instance.new("ObjectValue",h)
ov.Name = "creator"
ov.Value = game.Players:WaitForChild(cre.Name)
else
local ovs = h:GetChildren()
for i = 1,#ovs do
if (ovs[i].Name == "creator") then
ovs[i].Value = game.Players:WaitForChild(cre.Name) end
end
end
end
end
end
Handle.Touched:Connect(on)
I thought this would be simple to fix but I’m having a hard time figuring out what is wrong.