What is wrong with my math.clamp?

Right now, when I walk towards the objects, they appear as i get closer. I want them to dissapear as i get closer but I’m not too sure what i did wrong with clamps or anything. Can anyone help?

local player = game.Players.LocalPlayer
local MinDistance = 0 
local MaxDistance = 15

game:GetService("RunService").Heartbeat:Connect(function()
local character = player.Character or player.CharacterAdded:Wait()
local humanoidP = character.PrimaryPart
	for _, part : MeshPart in game.Workspace.trail:GetChildren() do
		local distance = (humanoidP.Position - part.Position).Magnitude
		part.Transparency = math.clamp(distance, MinDistance, MaxDistance) / MaxDistance
		print(distance)
	end
end)

3 Likes

btw i was printing the distance to test if distance was working as intended u can ignore that lol

2 Likes

RunService Seems to be the problem or something like that try to do the same thing and mess around with it try to figure out what may be wrong with it it can be a small debug

2 Likes

not 100% sure if that is the issue… idrk tho but still havent been able to reverse it

2 Likes

Try this:

part.Transparency = 1 - (math.clamp(distance, MinDistance, MaxDistance) / MaxDistance)

4 Likes

works like a charm thanks boss!

1 Like

Well let me know when you get fixed and all that :smiley:

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