Checking for the exact position is a bad idea instead you can use magnitude which checks the distance between two objects, this way you can check if the coin is close enough to each others.
local Part1 = "Part1 Here"
local Part2 = "Part2 Here"
local Distance = 3
if (Part1.Position - Part2.Position).magnitude < Distance then
-- Do stuff here
end
Ah thanks, but what if you don’t know the local parts yet? I got two folders filled with children teleporting to each other every moment. Is there a way to find the colliding parts first?
There is but may I ask what do you mean why two folders filled with children teleporting to each other every moment. Is the part like in separate places?
Ai, so i got a folder named “Grid”, there are like 20 invisible platforms in this folder, and I got another folder with power ups / coins. So I got a script that picks one random platform of the 20, then copies the position and pastes it in a cloned power up / coin.
I see in that case there are some solution to the problem if you want to check the distance between each parts are.
You can get all of the parts and compare it’s position with the selected part using :GetChildren()
local Distance = 3
for _,Coin in pairs(game.Workspace.CoinFolder) do
if Coin:IsA("BasePart") then -- Get Coin to compare
for _,CompareCoin in pairs(game.Workspace.CoinFolder) do
if CompareCoin:IsA("BasePart") and CompareCoin ~= Coin then
-- Get all coins once again from the folder and compare it with the current coin
-- With one condition that it won't select itself
if (Coin.Position - CompareCoin.Position).magnitde < Distance then
-- Do stuff here
end
end
end
end
end
You can use Region3 to check if there are any coins nearby the checked coin. (and use :Getchildren() once again just to check all of the coins)
local Distance = 3
for _,Coin in pairs(game.Workspace.CoinFolder) do
local Position1 = Coin.Position + Vector3.new(Distance, Distance, Distance)
local Position2 = Coin.Position - Vector3.new(Distance, Distance, Distance)
local Region = Region3.new(Position1, Position2)
for _,Part in pairs(game.Workspace:FindPartsInRegion3(Region, nil, math.huge)) do
if Part.Name == "COIN NAME" then
-- Do stuff here
end
end
end