local items = game:GetService("ReplicatedStorage").Buildings
game:GetService("ReplicatedStorage").ClientPlaced.OnServerInvoke = (function(player, itemName, location)
local itemTemplate = items:FindFirstChild(itemName)
if (itemTemplate) then
local item = itemTemplate:clone()
item:SetPrimaryPartCFrame(location)
local cScript = item:FindFirstChild("CoreScript")
if cScript then
cScript.Disabled = false
end
item:SetPrimaryPartCFrame(location)
if item.Name == "Mining Drill" then
local oreChecker = item:WaitForChild("OreChecker")
print(oreChecker.Parent)
local oreDeposits = oreChecker:GetTouchingParts()
print(oreDeposits[1])
for i, v in ipairs(oreDeposits) do
print(v)
if v.Parent.Parent == workspace.OreDeposit then
item.Parent = workspace.Base.ItemHolder
return true
end
end
return "No ore deposit found"
end
item.Parent = workspace.Base.ItemHolder
return true
end
return "Item Template doesn't exist."
end)
I have a part that should be on top of another part, and I’m trying to detect that using GetTouchingParts(). However, despite them being on top of each other and them both having canCollide turned on, it will always return nil.
I believe the issue is caused by not GetTouchingParts but instead by this operation:
Why? It is known that :SetPrimaryPartCFrame isn’t exactly accurate due to floating point errors from this post.
Consequently, it’s possible that the model is slightly levitating above the ground with a stud difference of 0.0000001 due to the aformentioned floating point error. To solve this maybe just move the model a bit more downwards I guess?
Ah, wasn’t aware of that. I apologize. I’ve been working with :GetTouchingParts() recently and had to do that, never actually read the API reference.
Hmm, perhaps there is a possibility that you are trying to detect contact the moment before the model movement occurs but I’m not really sure how :SetPrimaryPartCFrame moves the rest of the model relative to the primary part and if it’s synchronous or not.
Honestly, to debug the issue I would create a connection to run service every heartbeat and just print out what the clone of the model’s ore checker is detecting
--runservice connect to hearbeat
function ()
local oreDeposits = oreChecker:GetTouchingParts()
print(oreDeposits[1]) -- try detecting
end
Otherwise, it may even be a syntax error are you sure the part is called “OreChecker”? Maybe even the collision box of the oreDeposits if it’s a mesh, if so then maybe turn on complex collision detection for that.
Other possible solutions include using a different method to detect ore deposits such as raycasting.