Hello! I’ve used S_maritan’s tutorial to make a simple ore generation system, it works fine when I use click detectors, but when I use my main script to fire a remote event (partdelete) parts start spawning into one another and glitching. Any thoughts on what could cause the problem?
Here’s the code
local positions = {
Vector3.new(6,0,0);
Vector3.new(-6,0,0);
Vector3.new(0,6,0);
Vector3.new(0,-6,0);
Vector3.new(0,0,6);
Vector3.new(0,0,-6);
}
function Generate(pos)
if pos then
for _,pos2 in pairs(positions) do
local newPos = pos+pos2
local previouslyGenerated
for _,generated in pairs(workspace.Cubes.Generated:GetChildren()) do
if generated.Value == newPos then
previouslyGenerated = true
end
end
if newPos.Y > 0 then
previouslyGenerated = true
end
if not previouslyGenerated then
local ore = game.ServerStorage.Ores.Stone:Clone()
ore.Position = newPos
ore.Parent = workspace.Cubes
local val = Instance.new("Vector3Value")
val.Value = newPos
val.Parent = workspace.Cubes.Generated
end
end
end
end
for i,cube in pairs(workspace.Cubes:GetChildren()) do
if cube:IsA("Part") then
local val = Instance.new("Vector3Value")
val.Value = cube.Position
val.Parent = workspace.Cubes.Generated
end
end
game.ReplicatedStorage.partdelete.OnServerEvent:Connect(function(plr, ore)
local val = Instance.new("Vector3Value")
val.Value = ore.Position
val.Parent = workspace.Cubes.Generated
Generate(ore.Position)
ore:Destroy()
end)
Thanks!