How can I make a part's transparency 1 when it is touched by a player?

I have this script that makes the part’s transparency low when the player gets near them. Now i want to add to this script that when the player touches the part that the part’s transparency goes all the way invisible. I’ll also add a video for reference of what it looks like so you guys may get a better understanding.
Script:

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

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 = 1 - (math.clamp(distance, MinDistance, MaxDistance) / MaxDistance)
	end
end)


Go and check on another person,which also has math.clamp issue

are you referencing my earlier post? ha that was me and that problem was fixed unless there’s someone else with math.clamp problem? sorry im an intermediate scripter so im in the stage of barely any scripts work first try/figuring out new systems

No problems.helping is caring.we can continue to help u

1 Like

There is one on why is wrong with my math.clamp.Check that one out

Again I’m pretty sure thats my previous post. Everything is fixed with that one, i believe i also marked it with a solution, thank you though! Right now i’m trying to figure out how to make the parts dissapear after they are touched by the player.

That is ez,just have to do script.Parent.Touched:Connect(Function()

End

Okay I modified the script and it didn’t work heres what I did:

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

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 = 1 - (math.clamp(distance, MinDistance, MaxDistance) / MaxDistance)
		part.Touched:Connect(function() -- changes made starting here
			part.Transparency = 1 
		end)
	end
end)

One way I found that worked was part:Destroy(), however i don’t want to completely destroy the part because i want it to be able to come back in certain events (heres a quick example i made up: If player messes up and needs to restart trail, trail needs to come back visible for them)
Is there another thing I can use to remove the part temporarily?

SOLVED IT GUYS! So for my specific needs: I made the arrows go into a folder in starterpack after touched which makes them disappear but keep position, and not destroy. for testing purposes i put out a part at the end of the trail. I made the arrows go back to the original model in workspace if the part was touched, that worked like a charm making them visible again!!!

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