Hi! I’ve been trying to make an image less transparent as the player looks closer to an object, and make it more transparent once they look away. However I can’t figure out how to do it myself, since my code isn’t really working as intened. Because the magnitude is either 43 or 42, I get either ~0.43 or ~0.42 when i divide it by 0.01, and the difference between the two numbers is so small that the difference between the transparency of the picture is almost invisible. How to make it so the image is actually less and more transparent depending on how close is the ray’s end position to the object, so it’s actually visible? Here’s a part of code resposible for this:
RunService.RenderStepped:Connect(function()
if roundValue.Value == true then
local mousePosition = UserInputService:GetMouseLocation()
local mouseRay = camera:ViewportPointToRay(mousePosition.X, mousePosition.Y)
raycastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000, raycastParams)
local magnitude = math.round(((mouseRay.Origin + mouseRay.Direction) - animatronicFolder:GetChildren()[1].HumanoidRootPart.Position).Magnitude)
playerStatic.ImageTransparency = magnitude * 0.01
print(magnitude)
print(playerStatic.ImageTransparency)
end
end)