How to prevent the object from constantly being created

Hello fellow developers,

  • Currently, I’m trying to make a combat system in which when you click a sword appears in your hand and the animations play accordingly.

  • Although I’ve been able to get this to work in some sort of fashion, the issue is that when making the sword appear in the player’s hands the way the script is made as to which it creates a motor for the sword to be placed in their hands.

-- part of the script that makes it appear in the player's hand]
function swordmodule.equip(_char, _handle, _port)
	motor ="Motor6D", _char['Right Arm'])
	motor.Part0 = _char['Right Arm']
	motor.Part1 = _handle
	motor.C1 =, 0.0971527249, 0.0524852239, -3.83993531e-11, -0.000976632931, 0.999999523, -0.99906826, 0.0431613103, 4.21527402e-05, -0.0431613177, -0.999067664, -0.000975722854)
	motor.C0 =, -0.863999844, -0.013999939, -4.26901951e-11, -0.000976637821, 0.999999523, -8.74227482e-08, -0.999999464, -0.000976637704, 0.999999523, -8.74227126e-08, -4.26901743e-11)
	_port.Part1 = nil
  • In accordance with possible solutions, I’ve tried using a debounce in which if there is a motor already in the Right Arm then it would not appear again, although this did not result in the problem being fixed.
-- solutions I've tried
		if not _character["Right Arm"]:FindFirstChild("Motor") then
			swordmodule.equip(_character, _weapons.Weapon:WaitForChild("Handle"), _weapons.Sheath.Port:WaitForChild("Main"))	
  • Altogether I’m just looking for some answers for this; along with some tips and critique on my scripting if anything, I just got into scripting a while ago I’m new to using the Lua engine and I’d like to get better at using this.

  • Thank you for reading and any help is greatly appreciated.

Instead of detecting if there is a motor inside the right arm, you should instead detect if there is anything inside the arm apart from touch interest since you have to manually insert a instance inside that part.

Also, you should read headstackk’s animation tutorial. It’s helpful and can help in the future.

1 Like