Help with making a reloading system for my weapon

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)

Tool.Unequipped:Connect(function()
ContextActionService:UnbindAction()
end)

why is the code just starting on the same line (sry for that)

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)

It worked. Thx for solving it :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.