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
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