Part conditional isn't true, why?

This sometimes works and sometimes not. Why is it so inconsistent?
For some reason this part matching conditional doesn’t work despite returning the same parts on both client and server.

for _,v in workspace.Filter:GetDescendants() do
			if v:IsA("ProximityPrompt") then
				v.TriggerEnded:Connect(function()
					Replicated.Remotes.VVVVV:FireServer(v.Value.Value, "lol", {Key = "lol"})
				end)
			end
		end
--
local ReturnParted = ClientModule:ReturnSpecificParts(Character, 12, "VE")
print(ClientP) -- Client part on client passed to server
print(ReturnParted) -- Same part but fetched on servre
if ReturnParted == ClientP then -- Isn't true why?
--Module
function module:ReturnSpecificParts(Character, Distance, PartTy:string?):BasePart?
	for _,v in game:GetService("CollectionService"):GetTagged("VM") do
		if v:FindFirstChild("Value") then
			if (v.Value.Value.Position - Character.PrimaryPart.Position).Magnitude <= Distance then
				local Part:BasePart? = v.Value.Value
				if Part:GetAttribute("PartType") == PartTy then return Part end
			end
		end
	end
end

My approach is get the nearest part with a specific attribute, without the use of raycast but if raycast is possible please let me know.

7 Likes

They are the same instances though! Only one part with the attribute exists and like I said it sometimes work and sometimes not, it’s very inconsistent!

2 Likes

If I read the post correctly, you have a part fetched from the client, that should be the same part as the one in the server?

3 Likes

That is correct!

4 Likes

Well, I don’t understand why it sometimes happens and sometimes doesn’t. My best bet is the times that it doesn’t, that part might get some values changed? Maybe it’s unanchored and the position has changed?

3 Likes

It’s really not! The way client fetches it is from a proximity prompt object value and server does the same but using collectionservice on a certain folder that also holds the object value of the same part

3 Likes

Well, I’m going to bookmark this because it also interests me and I don’t have a computer right now. Could you explain what you are trying to do again, though? I might find a logical solution (roblox engineers making 600k+ a year try not to make something inconsistent: impossible).

4 Likes

I am just trying to detect if player is near a certain part with a attribute that’s all! I’m doing a part check for security purposes though it doesn’t work! I tried to use the module function on the client yet it still doesn’t work!

2 Likes

I see, I didn’t understand some of the intentions of the code because I’m guessing you cut it out, but to fix the main problem you asked for: ignore all that and simply go through every part, check if they have the attribute and, as you did in the final part of code, check the distance using the magnitude.

3 Likes

an iteration might work but it’ll cause performance and be slow, I thought of raycast but I’m not sure since I barely use it.

2 Likes

Why would an iteration cause performance issues? It’s a simple math operation. In the case of raycasts you’d also need to do the same, but checking each raycast that you “shot” for each part.

2 Likes

Like this?

function CheckNearC(Attribute)
	for _,v:Instance? in workspace:GetDescendants() do
		if v:GetAttribute("PartType") == Attribute then
			return v
		end
	end
end
2 Likes

Yes, but you’d need to check for the part that is the closest to your position.

2 Likes
function CheckNearest(Position, AttributeName, Attribute)
  if typeof(Position) ~= "Vector3" or typeof(AttributeName) ~= "string" then return end

  local nearest = nil
  for _, v in pairs(workspace:GetDescendants()) do

    if v:IsA("BasePart") and v:GetAttribute(AttributeName) == Attribute then

      local distance = (v.Position - Position).Magnitude

      if nearest == nil or distance < nearest then

        nearest = distance

      end

    end

  end

  return nearest
end
2 Likes

If you need to implement this with models too, you could check if an instance has an ancestor that is a model and then don’t evaluate the instance, but the pivot of the model.

Although be careful with nested models though. If you have models inside a model and those models have baseparts, you might want to check only the last ancestor which is a model (aka the “master” model).

3 Likes

Bump still need updates on this, it works like once per 10 playtests.

Any updates on this and why it happens?