Why it don't get the position

So this is my code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local modelFolder1 = ReplicatedStorage:WaitForChild("Stage1")
local modelFolder2 = ReplicatedStorage:WaitForChild("Stage2")

local function choseModels1()
	local models1 = modelFolder1:GetChildren()
	if #models1 == 0 then
		warn("Error")
		return nil
	end
	
	local randomIndex = math.random(1, #models1)
	return models1[randomIndex]
end

local selectedModel1 = choseModels1()
if selectedModel1 then
	local clone = selectedModel1:Clone()
	clone.Parent = game.Workspace
	clone:SetPrimaryPartCFrame(CFrame.new(6, 0.5, 9))
end

local function chooseModels2()
	local models2 = modelFolder2:GetChildren()
	if #models2 == 0 then
		warn("Error2")
		return nil
	end
	
	if selectedModel1.Name == "Incorrect" then
		warn("Error3")
		return nil
	else
		local randomIndex = math.random(1, #models2)
		return models2[randomIndex]
	end
end

local selectedModel2 = chooseModels2()
if selectedModel2 then
	local coordinates = selectedModel1.Part1.CFrame.Position
	local clone = selectedModel2:Clone()
	clone.Parent = game.Workspace
	clone:SetPrimaryPartCFrame(CFrame.new(coordinates))
end

As you can see, the code selects models from folders inside the Replicated Storage and randomly loads one. It also has a condition: if the first one is called “Incorrect”, theres no longer load. My problem is that local coordinates = selectedModel1.Part1.CFrame.Position doesen’t load the position correctly. I also load an image of the Replicated Storage. Hope anyone can help, ty!
image

To get the cframe of a model you can do model:GetPivot()

1 Like

Did you try using printing before getting the coordinates to see if its running?
Anyway, I recommend using selectedModel1:GetPivot() for the coordinate, and using clone:PivotTo(coordinates). There is a chance that getting the position and then creating CFrame causes some values to get lost, so changing those might make a difference.

1 Like

Still dont workm, they still appear randomly

What exactly do you mean by appearing randomly?

Instead of appearing one following the other, the second one appears further, not where it should appear.

Ik wait now it works, it was a problem with the position on the script. Ty 4 ur help!

1 Like