Need Help With Disappearing Part

Here’s my code:

This script is the child of a floating boulder that slowly disappears when you touch it, waits a few seconds, and then refreshes back to being visible

Here’s the issue:
The code works fine, but I want to make it so the boulder stops going transparent, then reappearing, going transparent, then reappearing even after the player moves off the boulder. When the player touches the boulder, the loop keeps going forever. Help?

Could you be a little more specific? Thanks

As I said here, the code keeps looping through even after the player has left the boulder.

Have you tried adding a debounce value?

Because when a player touches the part, it is not “the player” but all its parts, which will cause your code to be executed several times

Also if you want the Boulder to only activate if a player touches it you have to add a check for it, since with its current code it will activate when anything touches it, regardless if is a player or not.

You must check if there is a humanoid touching the part

boulder.Touched:Connect(function(TouchedPart)
if TouchedPart.Parent:FindFirstChild("Humanoid") then
-- Your code
end
end)

Because the part can be touched by others parts

The boulder is floating in the air and nothing is touching it so that shouldn’t affect it.

For the transparency you should be use the TweenService with a debounce

local TS = game:GetService("TweenService")

local Debounce = false
boulder.Touched:Connect(function(TouchedPart)
if Debounce then
return
end
if TouchedPart.Parent:FindFirstChild("Humanoid") then
Debounce = true
TS:Create(boulder,Tween.new(Time),{Transparency = 1}):Play()
boulder.CanCollide = false
wait(Time)
boulder.CanCollide = true
boulder.Transparency = 0
Debounce = false
end
end)

Agreed, but the transparency system works fine right now. The only issue is the loop going on forever.

You shouldn’t use the loop for the transparency only with the wait it should be work

It doesn’t fix your problem, but move your post to #help-and-feedback:scripting-support, or it might be removed, if you can’t report it and ask a moderator.

Totally thought this was that category, I was just in development discussion before making this thread so I likely got confused.

Yeah, but it still works just fine and accomplishes exactly what I need; that’s not the issue I’m trying to get addressed here. I do appreciate the advice though.