Entities spawning at the wrong place

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!

  2. What is the issue? Include screenshots / videos if possible!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

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!

Alright, so I am making a Rooms game. And I am making entities to make the game a bit harder. One of the entities include A60.
Everytime you open a door, a room is generated.
If the room number is above a specific number, there is a chance some of the entities can rush through the rooms and attack.
But when they do spawn, they spawn at the wrong place.
I expected them to spawn far away from the door and then I would tween them to the door, once the tween is completed they would disappear. But they didn’t rush through any of the rooms.
Turns out, they actually spawn in the template rooms.
Instead, I want them to spawn in the generated rooms, not the templates.
I tried changing the names of the generated rooms to make them a bit more different but that didn’t work.
So, if you can help me that would be very appreciated.
Code:

 local debounce = false
local Rooms = workspace.Rooms:GetChildren()
script.Parent.MouseClick:Connect(function()
	if debounce == false then
		debounce = true
		script.Parent.Parent.Open:Play()
		game.TweenService:Create(script.Parent.Parent, TweenInfo.new(0.5), {CFrame = script.Parent.Parent.Opened.CFrame}):Play()
		local RandomRoom = Rooms[math.random(1, #Rooms)]
		local NewRoom = RandomRoom:Clone()
		NewRoom.Name = "GeneratedRoom"
		workspace.RoomValue.Value = workspace.RoomValue.Value + 1
		NewRoom:PivotTo(script.Parent.Parent.Parent.Exit.CFrame)
		NewRoom.Parent = workspace.GeneratedRooms
		local number = workspace.RoomValue.Value
		NewRoom.Door.Sign.SurfaceGui.TextLabel.Text = "A-".. number
		local Ambient = game.Lighting.Ambient
		local newColor = Color3.new(Ambient.R-0.003, Ambient.G-0.003, Ambient.B-0.003)
		game.Lighting.Ambient =  newColor
		game.Lighting.OutdoorAmbient = newColor
		if workspace.RoomValue.Value > 60 then
			local random = Random.new()
			if random:NextInteger(1,5) == 5 then
				local A60 = workspace.Enemies.A60:Clone()
				A60.Position = -NewRoom.Exit.CFrame.LookVector * 100
				A60.Scream.Playing = true
				A60.Parent = workspace.SpawnedEnemies
				local tween1 = game.TweenService:Create(A60, TweenInfo.new(10), {Position = NewRoom.Exit.CFrame.LookVector * 20})
				tween1:Play()
				tween1.Completed:Wait()
				A60.Gone:Play()
				A60:Destroy()
			end
			end
			if workspace.RoomValue > 120 then
				local random = Random.new()
				if random:NextInteger(1,20) == 20 then
					local B60 = workspace.Enemies.B60:Clone()
					B60.Position = -NewRoom.Exit.CFrame.LookVector * 100
					B60.Parent = workspace.GeneratedRooms
					B60.Scream:Play()
					local tween = game.TweenService:Create(B60, TweenInfo.new(7), {Position = NewRoom.Exit.CFrame.LookVector * 20})
					tween:Play()
					task.wait(21)
					B60:Destroy()
					B60.Gone:Play()
				end
			end
			if workspace.RoomValue > 200 then
				local random = Random.new()
				if random:NextInteger(1,10) == 10 then
					local A200 = workspace.Enemies.A200:Clone()
					A200.Position = NewRoom.Exit.CFrame.LookVector * 100
					A200.Parent = workspace.GeneratedRooms
					A200.Spawn:Play()
					local tween = game.TweenService:Create(A200, TweenInfo.new(7, -1, true, 0), {Position = -NewRoom.Exit.CFrame.LookVector * 20})
					tween:Play()
					task.wait(21)
					A200:Destroy()
					A200.Gone:Play()
				end
		end
		if workspace.RoomValue > 400 then
			local random = Random.new()
			if random:NextInteger(1,30) == 30 then
				local B200 = workspace.Enemies.B200:Clone()
				B200.Position = NewRoom.Exit.CFrame.LookVector * 100
				B200.Parent = workspace.GeneratedRooms
				B200.Spawn:Play()
				local tween = game.TweenService:Create(B200, TweenInfo.new(5, -1, true, 0), {Position = -NewRoom.Exit.CFrame.LookVector * 20})
				tween:Play()
				task.wait(21)
				B200:Destroy()
				B200.Gone:Play()
			end
		end
		end
end)

This is my code, and if you can find a solution. That will be very appreciated, thank you!

1 Like

I just have one question, could you please put the code in DevForum format? Just add tree ` before and fatter the code

Oh, I am quite new to DevForum, I didn’t know that.

Please hover all of your code and hit ‘Ctrl + E’ to do preformatted text ← like this

1 Like

Oh, I didn’t realise I made so much mistakes!

1 Like