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)
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
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.
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!!!