Why is this returning false when both values are equal?

Nope, tried it as well. Doesn’t work

Edit: trying to upload the game but since theres more than 3200 meshparts and cities, it keeps freezing up

use one of the FuzzyEq functions and output region.Color, C3.Value, and the output of the function each time you get to this if statement
it’d help to see more info

print(
   "\nregion color:", region.Color,
   "\nC3:", countryName, workspace.CountryData[countryName].C3.Value,
   "\nisEquals:", areColorsEqual(
      region.Color,
      workspace.CountryData[countryName].C3.Value,
      0.005
   )
)

Printed both. Same colour, 0, 0.0627451, 0.690196

Solution:

ROBLOX seems to have messed up the colours completely. Not sure at what point this was done, not saying it was recent either.

local colour = Color3.fromRGB(255,255,255)for _,i in pairs(game:GetDescendants())do if i:IsA("MeshPart")or i:IsA("Part")then if i.Color==colour then i.Color=colour elseif i:IsA("Color3Value")then i.Value=colour end;end;end

Solution is to run this code in the command bar (make sure to replace colour with the RGB colour-code of the colour you want. Not an issue with my code, issue with ROBLOX.

1 Like

I just went through it
you were causing an issue by processing the same region multiple times

Output showing multiple matches

I edited the code a bit to log more

The Code Edited
function PositionToCoord(position)
	return math.deg(
		(math.acos(
			(position.Unit:Dot(
				(position * Vector3.new(1, 0, 1)
				).Unit)
			)))) * math.sign(
				position.Y
	), math.deg((math.acos((workspace.Baseplate.CFrame.LookVector.Unit.Unit:Dot(
		(position * Vector3.new(1, 0, 1)).Unit))))) * math.sign(position.X
	);
end;

function FuzzyEq(color0, color1, epsilon)
	return
		math.abs(color0.r - color1.r) < epsilon and
		math.abs(color0.g - color1.g) < epsilon and
		math.abs(color0.b - color1.b) < epsilon
end

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Visible=false
	
	for _,i in pairs(workspace.Baseplate.Cities["Turkey"]:GetChildren())do
		local region = workspace.Baseplate.Parts:FindFirstChild(i:GetAttribute("Region"))
		local params = RaycastParams.new()
		params.FilterType= Enum.RaycastFilterType.Include
		params.FilterDescendantsInstances = {workspace.Baseplate.Parts}
		local raycastResult = workspace:Raycast(i.Position, Vector3.new(0, -10, 0), params)
	
		
		local outputStr = ""
--[[
		outputStr = outputStr .. "\nregion = " .. tostring(region)
		outputStr = outputStr .. "\nraycastResult = " .. tostring(raycastResult)
		if raycastResult then
			outputStr = outputStr .. "\n\t.Instance = " .. tostring(raycastResult.Instance)
			if raycastResult.Instance then
				outputStr = outputStr .. "\n\t\t.Color = " .. tostring(raycastResult.Instance.Color)
				outputStr = outputStr .. "\nTurkey.C3.Value = " .. tostring(workspace.CountryData["Turkey"].C3.Value)
				outputStr = outputStr .. "\nFuzzyEq = " .. tostring(FuzzyEq(raycastResult.Instance.Color, workspace.CountryData["Turkey"].C3.Value, 0.005))
			end
		end
]]
		
		if
			region and
			raycastResult and
			raycastResult.Instance==region and
			FuzzyEq(
				raycastResult.Instance.Color,
				workspace.CountryData["Turkey"].C3.Value, 0.005
			)
		then
			outputStr = outputStr .. "\n" .. (tostring(region) .. " did match")
			region.Color=Color3.new(1.0, 1.0, 1.0)
		else
			outputStr = outputStr .. "\n" .. (tostring(region) .. " did not match")
		end
		print(outputStr)

		i.BrickColor=BrickColor.Red()
	end
	if (workspace.CountryData["Turkey"].Capital.Value).Parent.Name=="Turkey" then
		local drag1, drag2 = PositionToCoord(workspace.CountryData["Turkey"].Capital.Value.Position)
		_G.Drag1 = drag1;
		_G.Drag2 = drag2;
	else local drag1, drag2 = PositionToCoord(workspace.Baseplate.Cities["Turkey"]:GetChildren()[1].Position)
		_G.Drag1 = drag1;
		_G.Drag2 = drag2;
	end
end)

Because you were setting a region’s color after processing it the first time with region.Color=Color3.new(1.0, 1.0, 1.0) and changing the color from Really Red to White, the second time the loop hit a city with the same region, the color didn’t match anymore

1 Like

There’s several cities in one region which is why. It has to be processed this way since, in the full game, countries share provinces often.

Then the region colour would stay white. Instead, it stays as default value.

Edit: genuinely trying to understand this. it makes no sense since the most recent script i posted above solves the issue just by setting the colour back, even though it was already like that before. odd

yes, but that’s why you were having the issue earlier with “many provinces dont match up even though the colour is EXACTLY the same.”

and I’m checking now for the ones that don’t match
the issue looks like it’s caused by your raycasts hitting the wrong target


the raycast for Amasya is hitting Turkey.042 rather than Turkey.040
the raycast for Ereğli is hitting Turkey.022 rather than Turkey.032
the raycast for Manavgat is hitting nothing

The code used in testing
		if
			region and
			raycastResult and
			raycastResult.Instance==region and
			FuzzyEq(
				raycastResult.Instance.Color,
				workspace.CountryData["Turkey"].C3.Value, 0.005
			)
		then
			print("matched " .. tostring(i) .. " with " .. tostring(region))
			region.Color=Color3.new(1.0, 1.0, 1.0)
		else
			print("did not match " .. tostring(i) .. " with " .. tostring(region)
				.. "\nraycastResult.Instance = " .. tostring(raycastResult))
		end

Now it works but earlier, even without raycasting, it had issues. It is a mix of both.

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