Spawn script not working

So my dev made this script and I decided to duplicate it for another part. Its supposed to be when you click on a block it respawns somewhere on the main part but its not working, why?

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.MoonSpawnArea.Position.X + math.random(-workspace.MoonSpawnArea.Size.X/2, workspace.MoonSpawnArea.Size.X/2), rocks[i].Primary.Position.Y, workspace.MoonSpawnArea.Position.X + math.random(-workspace.MoonSpawnArea.Size.X/2, workspace.MoonSpawnArea.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

Isn’t it PrimaryPart and not Primary?

Also can you show the Output?

1 Like

Well I copied it from my devs script (Which worked) and heres the output:

Primary is not a valid member of part.

Why did my devs script work and not mine?

1 Like

Maybe Primary was a child of the original part.

1 Like

Ohh I get you. (30 charsssssssss)

1 Like

@ItsMeJakeZer is right I guess
Primary might be a child.

Now I have another issue, when I click it, it teleports but then just destroys itself :confused:

I haven’t checked the script entirely but I believe the part changes position and not being destroyed. I will check it over to see.

I have my explorer open, and suddenly, the block just is gone

hmm, is there another script acting on this part?

Also what is the name of the part that is being destroyed?

The part is called (its a model) MoonRock

Can you please post the second script, it might help.

local GotMoonRock = false
variables = require(game.ServerScriptService.Variables)
script.Parent.MouseClick:Connect(function(player)
	variables.CurrentMoonRock = variables.CurrentMoonRock +1
if variables.CurrentMoonRock >= 1 then
	GotMoonRock = true
end
if GotMoonRock == true then
player.PlayerGui.CollectionBook.MainFrame.MoonRock.Tick.Visible = true
end

end)

and also:

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

for i=1, #rocks, 1 do
	repeat
		rocks[i].Primary.CFrame = CFrame.new(workspace.MoonRockSpawnArea.Position.X + math.random(-workspace.MoonRockSpawnArea.Size.X/2, workspace.MoonRockSpawnArea.Size.X/2), rocks[i].Primary.Position.Y, workspace.MoonRockSpawnArea.Position.X + math.random(-workspace.MoonRockSpawnArea.Size.X/2, workspace.MoonRockSpawnArea.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

@ItsMeJakeZer Thats all the scripts.

I’ve looked through the scripts and can’t seem to find anything. Might be a glitch? Try looking for either :Destroy or .Parent

This script is just duplicated and the only thing changed is the names. The other script did not work like this.