So im making this gun and i want it to be reloadable, but i cant make it so it reloads with the key R. Can Someone please help?
When i use this code and press R i just get this in the output → Argument 3 missing or nil
Heres the code
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
Tool.Equipped:Connect(function(name, state, obj)
ContextActionService:BindAction(“Reload”, function()
if state == Enum.UserInputState.Begin then
ReloadEvent:FireServer()
end
end)
end)
end
end)
the error is because the ContextActionService:BindAction function is missing the third argument, which should be the inputObject.
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
Tool.Equipped:Connect(function()
ContextActionService:BindAction("Reload", function(Action, state, inputObj)
if state == Enum.UserInputState.Begin then
ReloadEvent:FireServer()
end
end, true, Enum.KeyCode.R)
end)
end
end)
Tool.Unequipped:Connect(function()
ContextActionService:UnbindAction("Reload")
end)