Clones Twice When It should Only Clone Once

So I am making a script that spawns a dummy into the workspace, and for some reason instead of spawning one it spawns two. I am on here to see if anybody knows any possible fixes/if I did something wrong. I looked around and can’t seem to find anything related to this, so I hope someone will help.

Screenshot:

local script:

local Humans = game.ReplicatedStorage:WaitForChild("Humans")


local tb = script.Parent.CarButton


tb.MouseButton1Click:Connect(function()
	for i, hum in pairs(Humans:GetChildren()) do
		game.ReplicatedStorage.humev.ChadSpawnRe:FireServer(hum)
		print("Yes!")
	end
end)

Server Script:

local Hums = {}


game.ReplicatedStorage.humev.ChadSpawnRe.OnServerEvent:Connect(function(plr, hum)
	
	
	
		
		
		local newHum = game.ReplicatedStorage.Humans.ChadTheCreator:Clone()
		
		local hrp = plr.Character.HumanoidRootPart
		
		newHum:SetPrimaryPartCFrame(hrp.CFrame + (hrp.CFrame.LookVector * 10) + Vector3.new(0, 10, 0))
		
		newHum.Parent = workspace
		
		Hums[plr] = newHum
	end)

You propably have 2 children inside Humans folder and
for loop loops 2 times and it sends remote event 2 times.
You can try adding if hum.Name == “ChadTheCreator” then inside the for loop:

for i, hum in pairs(Humans:GetChildren()) do
    if hum.Name == "ChadTheCreator" then
                game.ReplicatedStorage.humev.ChadSpawnRe:FireServer(hum)
		print("Yes!")
    end
end

Ah, thank you! I tried that and it works great now. I forgot I had another test dummy in there. Thanks for the help!

1 Like