Trying to fix this zombie infecting script

The script works perfectly fine, however once the player gets infected and infects another player they dont get the arms duplicated to them, instead it duplicates to the player that was infected first so now the infected player has 4 pairs of arms.

wait(1)
owner=script.Parent.Parent.Name

function onTouched(part)
	if part.Parent ~= nil then
		local h = part.Parent:findFirstChild("Humanoid")
			if h~=nil then
				if cantouch~=0 then
					if h.Parent.Name~=owner then
						
						if h.Parent:findFirstChild("zarm")~=nil then return end

						cantouch=0

						local larm=h.Parent:findFirstChild("Left Arm")
						local rarm=h.Parent:findFirstChild("Right Arm")
						
						if larm~=nil then
							larm:remove()
						end
						if rarm~=nil then
							rarm:remove()
						end
						local zee= script.Parent.Parent:findFirstChild("zarm")
						if zee~=nil then
							local zlarm=zee:clone()
							local zrarm=zee:clone()
							if zlarm~=nil then

							local rot=CFrame.new(0, 0, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
								zlarm.CFrame=h.Parent.Torso.CFrame * CFrame.new(Vector3.new(-1.5,0.5,-0.5)) * rot
								zrarm.CFrame=h.Parent.Torso.CFrame * CFrame.new(Vector3.new(1.5,0.5,-0.5)) * rot
								zlarm.Parent=h.Parent
								zrarm.Parent=h.Parent
								zlarm:makeJoints()
								zrarm:makeJoints()
								zlarm.Anchored=false
								zrarm.Anchored=false
								wait(0.1)
								h.Parent.Head.Color=zee.Color
							else print("no zee"); return end
						end
						wait(1)
						cantouch=1
					end
				end
			end
	end
end

script.Parent.Touched:connect(onTouched)

Try changing “:remove()” to “:Destroy()” in this part:

For more info see this:
https://developer.roblox.com/recipes/Remove-a-Limb-from-a-Player

Fixed Code
wait(1)
owner=script.Parent.Parent.Name

function onTouched(part)
	if part.Parent ~= nil then
		local h = part.Parent:findFirstChild("Humanoid")
			if h~=nil then
				if cantouch~=0 then
					if h.Parent.Name~=owner then
						
						if h.Parent:findFirstChild("zarm")~=nil then return end

						cantouch=0

						local larm=h.Parent:findFirstChild("Left Arm")
						local rarm=h.Parent:findFirstChild("Right Arm")
						
						if larm~=nil then
							larm:Destroy()
						end
						if rarm~=nil then
							rarm:Destroy()
						end
						local zee= script.Parent.Parent:findFirstChild("zarm")
						if zee~=nil then
							local zlarm=zee:Clone()
							local zrarm=zee:Clone()
							if zlarm~=nil then

							local rot=CFrame.new(0, 0, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
								zlarm.CFrame=h.Parent.Torso.CFrame * CFrame.new(Vector3.new(-1.5,0.5,-0.5)) * rot
								zrarm.CFrame=h.Parent.Torso.CFrame * CFrame.new(Vector3.new(1.5,0.5,-0.5)) * rot
								zlarm.Parent=h.Parent
								zrarm.Parent=h.Parent
								zlarm:makeJoints()
								zrarm:makeJoints()
								zlarm.Anchored=false
								zrarm.Anchored=false
								wait(0.1)
								h.Parent.Head.Color=zee.Color
							else print("no zee"); return end
						end
						wait(1)
						cantouch=1
					end
				end
			end
	end
end

script.Parent.Touched:connect(onTouched)
1 Like

I’m curious, why so many deprecated functions?

Also, there is good reason to change :remove() to :Destroy()

everything works, if the player infects another player they dont get the arms

Please do not ask for people to fix scripts you didn’t make with broad problems. If you have a more broad issue, that’d be more acceptable.