Rock move script

Me and my devs made a script so where you clicked on the part it would teleport it somewhere on the baseplate. I added little decorations on the rock and it tp’s the rock but not the decorations on the rock. Why?
Screen Shot 2020-08-23 at 4.50.24 pm

script 1:

rocks = workspace.Rocks:GetChildren()
touching = false
touchingparts = {}

for i=1, #rocks, 1 do
	rocks[i].Primary.ClickDetector.MouseClick:Connect(function()
		repeat
			touching = false
			rocks[i].Primary.CFrame = CFrame.new(workspace.RockSpawnArea.Position.X + math.random(-workspace.RockSpawnArea.Size.X/2, workspace.RockSpawnArea.Size.X/2), rocks[i].Primary.Position.Y, workspace.RockSpawnArea.Position.X + math.random(-workspace.RockSpawnArea.Size.X/2, workspace.RockSpawnArea.Size.X/2))
			touchingparts = rocks[i].Primary:GetTouchingParts()
			for c=1, #touchingparts, 1 do
				if touchingparts[c].Name == "terrain" then
					touching = true
					break
				end
			end
		until touching == false
	end)
end


script 2:

rocks = workspace.Rocks:GetChildren()
touching = false
touchingparts = {}

for i=1, #rocks, 1 do
	repeat
		rocks[i].Primary.CFrame = CFrame.new(workspace.RockSpawnArea.Position.X + math.random(-workspace.RockSpawnArea.Size.X/2, workspace.RockSpawnArea.Size.X/2), rocks[i].Primary.Position.Y, workspace.RockSpawnArea.Position.X + math.random(-workspace.RockSpawnArea.Size.X/2, workspace.RockSpawnArea.Size.X/2))
		touchingparts = rocks[i].Primary:GetTouchingParts()
		for c=1, #touchingparts, 1 do
			if touchingparts[c].Name == "terrain" then
				touching = true
				break
			end
		end
	until touching == false
end
3 Likes

why not make it a model and do model:SetPrimaryPartCFrame

1 Like

You should do this

model.PrimaryPart.CFrame = (the object you want to move it to).CFrame

or

model.PrimaryPart.CFrame = CFrame.new(“Enter co-ordinates here”)

1 Like

its not supposed to tp to the baseplate its supposed to teleport anywhere on/near the baseplate.

do something like this

model.PrimaryPart.CFrame = CFrame.new(math.Random(),math.Random(),1)

1 Like

replace it with what you are currently using to move the rock

Model.Primary part would only move the primary part right?
I am a rookie and i understand NOTHING your saying
This was not written by me, most of it is by my dev.

ok do the line I wrote earlier plus all the other parts of the model

nvm that wont work

I can write a more detailed explaination this time tomorrow

if you want to move the whole model, you can also use

model:MoveTo(Vector3.new(0,0,0))

I do not want to move the model to a place, it needs to be random (but still on the baseplate)

create some locations for where the rocks can be in a table, and then randomly choose a position from the table and move the model to that location

But my issue is, yesterday everything was fine, I come to studio today and stuff is glitching…