Problem with finding object position

Hi, i have a script that sould check for the Magnitude of 2 objects. The script gives an error.

if hit and (hit:IsA("Terrain") or hit.Name:lower() == "terrain") and HRP.Position - clientStructure.Position.Magnitude < maxPlacingDistance or HRP.Position - clientStructure.OpenPart.Position.Magnitude < maxPlacingDistancethen then
-- Error
Position is not a valid member of Model "Workspace.DimensionalChest"

The “DimensionalChest” (clientStructure) element is a Model, so i checked with a or for the PrimaryPart

Strangely enough, it seems to work on elements other than Terrain

check if the thing you are trying to get the position of is a BasePart

The part inside the model is a BasePart

check if there’s the name of your part inside that model

if hit then
   if not hit:FindFirstChild(Part.Name) then return end

Yea OpenPart is child of the model (clientStructure)

local structurePart = clientStructure.PrimaryPart or clientStructure:FindFirstChild("OpenPart")

if (structurePart) then
    local distanceFromStructure = (structurePart.Position - HRP.Position).Magnitude

    if (hit:IsA("Terrain") and (distanceFromStructure <= maxPlacingDistance)) then
        -- Do stuff here

Try this out

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.