Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't it teleport the zombies randomly?

Trying to make it teleport them all individually once to random coordinates to be spaced out and automated, but it won't teleport them at all. If I do this script without checking for the name it teleports them all to the same place. Why isn't it working?

local bool = game.ReplicatedStorage.value.roun -- boolvalue
local zombw = game.Workspace["coolboi"] -- unimportant
local drool = game.ReplicatedStorage.objects["Drooling Zombie"] -- mob
local zombie = game.ReplicatedStorage.value.zombie -- zombie amount
local rounds = game.ReplicatedStorage.value.roundn -- round number

bool.Changed:Connect(function(newval) -- checking if true
	if bool.Value == true then -- if value is true
		zombw:Destroy() -- unimportant
		rounds.Value = rounds.Value + 1 -- add value to round
		local potato = zombie.Value -- just localizing zombie value
		potato = rounds.Value *4 -- changing value to rounds x 4
		for i = 1,potato do  
			local drools = drool:Clone()-- cloning desired amount of zombies
			drools.Parent = game.Workspace -- zombies parent
				if drools.Name ~= ("Zombie")then  -- chcking the name
						drools.PrimaryPart = drools:FindFirstChild("HumanoidRootPart") -- getting part
					drools.PrimaryPart.Position = Vector3.new(math.random(-350,-156),.5,math.random(-236,-13)) drools.Name = ("Zombie") -- randomizing position within plate
					drools.Name = ("Zombie") -- changing name
						repeat until drools.Name == ("Zombie") -- making sure all have --same name and tele and to repeat
					elseif drools.Name == ("Zombie") then print ("ZFound") end -- if they --do have the name print and end
						end
					end
			end)
				
	
	




1 answer

✓ Accepted answer
bool.Changed:Connect(function(newval) -- checking if true
	if bool.Value == true then -- if value is true
		zombw:Destroy() -- unimportant
		rounds.Value = rounds.Value + 1 -- add value to round
		local potato = zombie.Value -- just localizing zombie value
		potato = rounds.Value *4 -- changing value to rounds x 4
		for i = 1,potato do  
			local drools = drool:Clone()-- cloning desired amount of zombies
			drools.Parent = game.Workspace -- zombies parent
			if drools.Name ~= ("Zombie")then  -- chcking the name
				drools.Name = ("Zombie") -- changing name
			elseif drools.Name == ("Zombie") then 
				print ("ZFound") 
			end
			drools.PrimaryPart = drools:FindFirstChild("HumanoidRootPart") -- getting part
			drools.PrimaryPart.Position = Vector3.new(math.random(-350,-156),.5,math.random(-236,-13))
		end
	end
end)

Try this.

Your repeat loop was rather pointless. The previous line literally changes the name so the loop has no real use. Following that the teleport code was only used on those who didn't already have the name "Zombie". Moving it outside and after the if statement works well in this case.

This discussion is preserved as it was. New answers, comments, and votes are closed.