Script not identifying when i'm in a certain distance

I’m working on a script that checks when the character is on a distance to make something invisible, here is the script: (Sorry for the format)

game:GetService("RunService").RenderStepped:Connect(function()
	local Stuff = game:GetService("Workspace"):GetDescendants()
	for _, Object in pairs(Stuff) do
		if Object:IsA("Part") then
			local _LowDetail = Object:FindFirstChild("_LowDetail")
			if _LowDetail then
				if _LowDetail.Value then
					local Character = Player.Character
					if Character then
						local PrimaryPart = Character.PrimaryPart
						if PrimaryPart then
							local Distance = (PrimaryPart.Position - Object.Position).Magnitude
							if Distance >= Object:FindFirstChild("_LowDetailDistance").MaxValue then
								Object.Transparency = 1
							elseif Distance <= Object:FindFirstChild("_LowDetailDistance").MaxValue then
								Object.Transparency = 0.75
							elseif Distance <= Object:FindFirstChild("_LowDetailDistance").MinValue then
								Object.Transparency = 1
							end
						end
					end
				end
        		end
		end
	end
end)

You might have seen that it checks if the character is on 3 different distances, one if the character is in a distance where the part would be invisible, the other would be if the character is in a distance where the part is semi-visible, and the other would be if the character is in a distance where the part is visible, and now, the problem is that the part that checks if the character is in a distance where the part is VISIBLE is not working, that means, when i’m in the distance of <15 studs far to the part My grammar is bad and i know it B) , it’s not visible completely, it’s still semi-visible, and i don’t know what i could to to fix it. I hope you help me, thanks for reading.

1 Like

To make a part visible, set the Object.Transparency to 0. I noticed that no matter what distance away from the character the part is, it’s always either invisible (Object.Transparency is 1) or semi-visible (Object.Transparency is .75).

Yeah, i know, but that is what is not working. When im in the distance where the object must be visible, it doesn’t. it stays semi-visible.

That may be because you’re never setting Object.Transparency to 0 when it should be visible.

1 Like

Ignore that i set Object.Transparency to 1, when i had to set it to 0:

I just wrote it to test it, however, here is some footage of this issue:
Distance where the part is invisible:


Distance where the part is semi-visible:

Distance where the part should be visible, when it’s not:

Try this out:

if Distance >= Object:FindFirstChild("_LowDetailDistance").MaxValue then
	Object.Transparency = 1 -- transparency above or equal to max value
elseif Distance < Object:FindFirstChild("_LowDetailDistance").MaxValue then
	if Distance < Object:FindFirstChild("_LowDetailDistance").MinValue then
		Object.Transparency = 0 -- transparency equal to or below min value
	else
		Object.Transparency = 0.75 -- transparency in between min and max value
	end
end
2 Likes