I'm trying to make a placing system and this has been killing me for hours. I'm attempting to get the positions of parts so people can't place them close together. Unfortunately, the loop makes my building script to where too much money is taken (since it loops for each boundary) and adding a debounce only checks from one part. Is there another way I could get the descendants' properties without the loop?
Server Script under ServerScriptService
game.ReplicatedStorage.BuildingFunctions.Boundary.OnServerEvent:Connect(function(player, position)
if workspace.PlayerBases[player.Name] then
local folder = workspace.PlayerBases[player.Name]
if not folder:FindFirstChild("Boundary") then
local Boundaries = workspace.PlayerBases:GetDescendants()
local Boundary = game.ServerStorage.BuildingStuff.Boundary:Clone()
Boundary.CanCollide = false
Boundary.Anchored = true
Boundary.Position = position
local OneBoundary = Boundaries["Boundary"]
if not OneBoundary then
player.leaderstats.Money.Value = player.leaderstats.Money.Value -150
Boundary.Parent = workspace.PlayerBases[player.Name]
else
for i, v in pairs(Boundaries) do -- The annoying loop
if v.Name == Boundaries then
if (v.Position - Boundary.Position).Magnitude <= 120 then
Boundary:Destroy()
else
player.leaderstats.Money.Value = player.leaderstats.Money.Value -150
Boundary.Parent = workspace.PlayerBases[player.Name]
end
print(v.Position)
print((v.Position - Boundary.Position).Magnitude)
print("a")
end
end
end
end
end
end)
--The OneBoundary is so the first player could place their Boundary since the loop won't run until one is placed
