Clone happened multiple time

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    i want to make a pirate game and when you use sword and kill someone their limbs get cut off
    like a little cool extra thing for the game

  2. What is the issue? Include screenshots / videos if possible!
    when i use sword and kill the dummy their limbs get cut off the blood effect and sound effect get clone so many instead of one
    https://gyazo.com/d31bdfdbf13c7fa1c06601f0d4f3338d

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i spend 2 days try every solution i can and none work and i also search on dev forum and no one has the same proplem i have

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
this is my first time use dev forum and call for help btw
if i miss something obvious im sorry i still have many thing to learn im not completely good

also image of the tool
https://gyazo.com/cec47e66f945d4b4e3c766b4c2f792a1
https://gyazo.com/c944895b93abd52f99d9510264003de0

---script 2
local script2 = script.Parent.Parent.Parent.Script
local slashdecal = script2.SlashDecal1:Clone()
local slashdecal2 = script2.SlashDecal2:Clone()
local slashdecal3 = script2.SlashDecal3:Clone()
local sfx1 = script2.Slash1:Clone()
local sfx2 = script2.Slash2:Clone()
local bloodparticles = script2.BloodParticles
local blood1 = bloodparticles.Blood1:Clone()
local blood2 = bloodparticles.Blood2:Clone()
local blood3 = bloodparticles.Blood3:Clone()
local blood4 = bloodparticles.Blood4:Clone()
local BloodParticleAttachment = Instance.new("Attachment")
blood1.Parent = BloodParticleAttachment
blood2.Parent = BloodParticleAttachment
blood3.Parent = BloodParticleAttachment
blood4.Parent = BloodParticleAttachment

local hitTable = {}

	

script.Parent.Parent.Parent.Blade.Touched:Connect(function(hit: BasePart)
	local enemy = hit.Parent
	local eHum = enemy:FindFirstChildOfClass("Humanoid")
	local eHrp = enemy.PrimaryPart or eHum.RootPart

	if enemy and eHum and eHrp and eHum.Health > 0 and not hitTable[enemy] then
		hitTable[enemy] = true
		
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
	local uppertorso = hit.Parent:FindFirstChild("UpperTorso")
	local rightua = hit.Parent:FindFirstChild("RightUpperArm")
	local rightla = hit.Parent:FindFirstChild("RightLowerArm")
	local righthand = hit.Parent:FindFirstChild("RightHand")
	local leftua = hit.Parent:FindFirstChild("LeftUpperArm")
	local leftul = hit.Parent:FindFirstChild("LeftUpperLeg")
		local debris = game:FindFirstChild("Debris")

	local animation = script.Animation
	
	script.Disabled = true
	
	local animationtrack = humanoid:LoadAnimation(animation)
	
	local decalorder = math.random(1,3)
	local decalplace = math.random(1,4)
	if decalplace == 1 then
			slashdecal.Parent = uppertorso
		elseif decalplace == 2 then
				slashdecal2.Parent = rightua
			elseif decalplace == 3 then
					slashdecal3.Parent = leftua
				elseif decalplace == 4 then
						slashdecal.Parent = leftul
	end
	
	animationtrack:Play()
	BloodParticleAttachment.Parent = uppertorso
	blood1:Emit(25)
	blood2:Emit(25)
	blood3:Emit(25)
	blood4:Emit(25)
	debris:AddItem(BloodParticleAttachment, 2)
	debris:AddItem(sfx1, 2)
	debris:AddItem(sfx2, 2)
	debris:AddItem(slashdecal, 2)

		eHum:TakeDamage(30)
		print("player has been damage")

		--coroutine.resume(coroutine.create(function()
		local slashSFX = script.Parent.Parent.Parent.Script.Slash1:Clone()
		slashSFX.Parent = eHrp
		slashSFX:Play()

		task.delay(slashSFX.TimeLength or 3, slashSFX.Destroy, slashSFX)
		--end))
		
--- proplem happend from this part i think
		humanoid.Died:Connect(function()
			print("player dead")
			local limbgoreattachement = script.Parent.Parent.Parent.Handle.LimbBloodParticles:Clone()
			local sfx3 = script2:FindFirstChild("Slash3"):Clone()
			local sfx4 = script2:FindFirstChild("GoreSplash"):Clone()
			local sfx5 = script2:FindFirstChild("GoreSplash2"):Clone()
			limbgoreattachement.Parent = rightua
			sfx3.Parent = eHrp
			sfx4.Parent = eHrp
			sfx5.Parent = eHrp
			sfx5:Play()
			sfx4:Play()
			sfx3:Play()
			sfx1:Stop()
			sfx2:Stop()
			limbgoreattachement.LimbBlood1.Enabled = true
			limbgoreattachement.LimbBlood2.Enabled = true
			limbgoreattachement.LimbBlood3.Enabled = true
			limbgoreattachement.LimbBlood4.Enabled = true
			rightla.Parent = game.Workspace
			rightla.CFrame = rightla.CFrame
			rightla.OriginalSize:Destroy()
			rightla.RightElbowRigAttachment:Destroy()
			rightla.RightElbow:Destroy()
			rightla.RightWristRigAttachment:Destroy()
			rightla.CanCollide = true
			rightla.Anchored = false
			debris:AddItem(rightla, 10)
			debris:AddItem(righthand, 10)
			debris:AddItem(limbgoreattachement, 10)
			debris:AddItem(sfx3, 2)
			debris:AddItem(sfx4, 2)
				debris:AddItem(sfx5, 2)
		end)

	end

end)
---script1
--- this script is when active script 2
script.Parent.Activated:Connect(function()
	
	script.Disabled = true
	
	local animation = script.Animation
	local humanoid = script.Parent.Parent.Humanoid
	
	local animationtrack = humanoid:LoadAnimation(animation)
		animationtrack:Play()
	
	script.Parent.Handle.MeshPart.Script.Disabled = false
	
	wait(1)
	
	script.Disabled = false
	
	script.Parent.Handle.MeshPart.Script.Disabled = true
	
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Try using a debounce to prevent the code from running many times.

1 Like

I tried it was not the problem.

I’m pretty sure it has to do with debounce because this usually often occurs with touch events where they fire multiple times instead of once. Make sure to add a wait() as well. Here I’ll help you. Maybe you don’t know how to use or create debounces.

Lets start with a true or false variable

local debounce = false -- sets it to false

Now you want to first check if the debounce variable is equal to false or not, set it to true to prevent it from running again, wait a few seconds, and finally, change the value to false again so the code would be able to run again. By your code it would be:

script.Parent.Parent.Parent.Blade.Touched:Connect(function(hit: BasePart)
	if not debounce then -- if debounce is equal to false
	    debounce = true -- Switches it to true to prevent it from running any further.
	-- this is where the rest of the code will run:
		local enemy = hit.Parent
		local eHum = enemy:FindFirstChildOfClass("Humanoid")
		local eHrp = enemy.PrimaryPart or eHum.RootPart
	
		if enemy and eHum and eHrp and eHum.Health > 0 and not hitTable[enemy] then
			hitTable[enemy] = true
			
				local humanoid = hit.Parent:FindFirstChild("Humanoid")
		local uppertorso = hit.Parent:FindFirstChild("UpperTorso")
		local rightua = hit.Parent:FindFirstChild("RightUpperArm")
		local rightla = hit.Parent:FindFirstChild("RightLowerArm")
		local righthand = hit.Parent:FindFirstChild("RightHand")
		local leftua = hit.Parent:FindFirstChild("LeftUpperArm")
		local leftul = hit.Parent:FindFirstChild("LeftUpperLeg")
			local debris = game:FindFirstChild("Debris")
	
		local animation = script.Animation
		
		script.Disabled = true
		
		local animationtrack = humanoid:LoadAnimation(animation)
		
		local decalorder = math.random(1,3)
		local decalplace = math.random(1,4)
		if decalplace == 1 then
				slashdecal.Parent = uppertorso
			elseif decalplace == 2 then
					slashdecal2.Parent = rightua
				elseif decalplace == 3 then
						slashdecal3.Parent = leftua
					elseif decalplace == 4 then
							slashdecal.Parent = leftul
		end
		
		animationtrack:Play()
		BloodParticleAttachment.Parent = uppertorso
		blood1:Emit(25)
		blood2:Emit(25)
		blood3:Emit(25)
		blood4:Emit(25)
		debris:AddItem(BloodParticleAttachment, 2)
		debris:AddItem(sfx1, 2)
		debris:AddItem(sfx2, 2)
		debris:AddItem(slashdecal, 2)
	
			eHum:TakeDamage(30)
			print("player has been damage")
	
			--coroutine.resume(coroutine.create(function()
			local slashSFX = script.Parent.Parent.Parent.Script.Slash1:Clone()
			slashSFX.Parent = eHrp
			slashSFX:Play()
	
			task.delay(slashSFX.TimeLength or 3, slashSFX.Destroy, slashSFX)
			--end))
			
	--- proplem happend from this part i think
			humanoid.Died:Connect(function()
				print("player dead")
				local limbgoreattachement = script.Parent.Parent.Parent.Handle.LimbBloodParticles:Clone()
				local sfx3 = script2:FindFirstChild("Slash3"):Clone()
				local sfx4 = script2:FindFirstChild("GoreSplash"):Clone()
				local sfx5 = script2:FindFirstChild("GoreSplash2"):Clone()
				limbgoreattachement.Parent = rightua
				sfx3.Parent = eHrp
				sfx4.Parent = eHrp
				sfx5.Parent = eHrp
				sfx5:Play()
				sfx4:Play()
				sfx3:Play()
				sfx1:Stop()
				sfx2:Stop()
				limbgoreattachement.LimbBlood1.Enabled = true
				limbgoreattachement.LimbBlood2.Enabled = true
				limbgoreattachement.LimbBlood3.Enabled = true
				limbgoreattachement.LimbBlood4.Enabled = true
				rightla.Parent = game.Workspace
				rightla.CFrame = rightla.CFrame
				rightla.OriginalSize:Destroy()
				rightla.RightElbowRigAttachment:Destroy()
				rightla.RightElbow:Destroy()
				rightla.RightWristRigAttachment:Destroy()
				rightla.CanCollide = true
				rightla.Anchored = false
				debris:AddItem(rightla, 10)
				debris:AddItem(righthand, 10)
				debris:AddItem(limbgoreattachement, 10)
				debris:AddItem(sfx3, 2)
				debris:AddItem(sfx4, 2)
					debris:AddItem(sfx5, 2)
			end)
	
		end
	    wait(2) -- sets a cooldown just in case it is touched again. 
        debounce = false -- sets it to false so it can run again
	end
end)
2 Likes