Part duplicating and the clone is in the sky for some reason?

Ok so I have a script that basically what it does is spawning a monster in a random room. Im using an invisible part for the Cframe of the monster and that works fine. The problem is that to make sure I don’t spawn two monsters in the same room I change the invisible part parent to another folder. But for some reason it creates a clone of the part that is really up in the sky. To be clear in the script I don’t clone or duplicate the part in any way, I’m just changing the parent.
image2
image3
I have no idea what is happening so yeah I need some help. (Btw it doesn’t print any errors and the script is a local script)

2 Likes

Show the script please lol, its pretty hard to guess whats happenning without seeing your script.

1 Like

Here’s the script.

--Other parts of the script
elseif Number >= 90 then
			local Rooms = game.Workspace.AnomalyFolder:GetChildren()
			local anomalyroom = Rooms[math.random(1, #Rooms)]
			
			local Anomalies = game.Workspace.MonstersFolder.Flawed:GetChildren()
			local chosenMonster = Anomalies[math.random(1, #Anomalies)]
			
			chosenMonster.Parent = game.Workspace.UsedAnomalysFolder
			
			local Positions = game.Workspace.MonsterPositions:GetChildren()
			local chosenPosition = Positions[math.random(1, #Positions)]
			
			chosenPosition.Parent = game.Workspace.PositionsUsed
			
			print(chosenPosition.Parent)
			
			local CameraRoom = nil

			if anomalyroom.Name == "Kitchen" then CameraRoom = 1 end
			if anomalyroom.Name == "BedRoom" then CameraRoom = 2 end
			if anomalyroom.Name == "LivingRoom" then CameraRoom = 3 end
			if anomalyroom.Name == "Basement" then CameraRoom = 4 end
			if anomalyroom.Name == "Storage" then CameraRoom = 5 end
			if anomalyroom.Name == "Bathroom" then CameraRoom = 6 end
			if game.Players.LocalPlayer.PlayerGui.Security.SecurityHandler.RoomValue.Value == CameraRoom then
				local Tween = game:GetService("TweenService"):Create(game.Lighting.ColorCorrection, TweenInfo.new(.25, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, true, 0), {TintColor = Color3.new(0,0,0)})
				Tween:Play()
				wait(.25)
				
				local Monster = chosenMonster:Clone()
				Monster.Parent = game.Workspace.AnomalyWorkingFolder
				Monster.RootPart.CFrame = chosenPosition.CFrame
				
				Monster:WaitForChild("Room").Value = anomalyroom.Name
			else
				local Monster = chosenMonster:Clone()
				Monster.Parent = game.Workspace.AnomalyWorkingFolder
				Monster.RootPart.CFrame = chosenPosition.CFrame
				
				Monster:WaitForChild("Room").Value = anomalyroom.Name
			end
		end
--Other parts of the script
1 Like

I cant seem to figure out the issue either. Try adding a wait after (and maybe before) parenting the chosenPosition to see when exactly the second thing gets added

1 Like

It gets added at the exact same time. Btw the “PositionsUsedFolder” is only used in this script so I don’t understand what’s happening.

idk, try printing out positions and chosenPosition

(also, is this script segment by any chance in an event? if so, check if theres any possibility that the event got connected twice or something)

First of all, the script is a loop that at random times it spawns a random thing. And it’s not printing twice because at the end I have 1 monster but 2 parts, one in the correct position and the other one in the sky. Btw i tried changing the folder to another one but the clone is in the new folder aswell.

strange, but what exactly does positions and chosenPosition print out?

Also, try setting chosenPosition to a non-random part (doesn’t have to be in any specific folder), would it still clone itself?

I’m pretty sure that is a Studio bug so I guess I will have to work with this. By adding this at the end it looks like it works.

			for i, v in pairs(workspace.PositionsUsed:GetChildren()) do
				if v.Name == chosenPosition.Name then
					if v.Position == Vector3.new(0, 10000000000, 0) then
						v:Destroy()
					end
				end
			end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.