Problem with disappearing local parts!

are there any errors in the output?

no there are not… I will add some print statements

alright, tell me what happens when you’re finished.

Ok just finished. Nothing prints. I put a print statement right after the part is touched, but it doesn’t print that at all so I am very confused.

here the only difference is defining the part right away:

local part = script.Parent
part.Touched:Connect(function(hit)
if hit.Parent.Name == game.Players.LocalPlayer.Name then
part.Transparency = 0.75
part.CanCollide = false
wait(2.5)
part.Transparency = 0.25
part.CanCollide = true
end
end)

Tested it, and it doesn’t work…

here lemme check one of my games I had a script sort of like this.

this is the exact script I had:

game.Workspace.ShopOpen.Touched:Connect(function(hit)
	if hit.Parent.Name == game.Players.LocalPlayer.Name then
             --Code here
       end
end)

You didn’t put it in the part though, so where did you put it?

it was in startergui for it to open a gui so you dont need to put it under startergui unless you want to open a gui

Re: the long exchange above: LocalScripts won’t run in the workspace, @sniper74will.

Use one LocalScript in StarterPlayerScripts and use a loop to add a touched connection to all the parts of interest.

Use CollectionService, or put them all into a folder on their own to make it easy to just grab the parts you care about.

Here’s a quick example with using a folder or model to contain only the parts that want to disappear:

local player = game.Players.LocalPlayer

for _, part in ipairs( game.Workspace.MyDisappearingParts:GetChildren() ) do
    local debounce = false
    part.Touched:Connect( function( hit )
        if not debounce and player.Character and hit:IsDescendantOf( player.Character ) then
            debounce = true
            wait( 0.25 )
			part.Transparency = 0.75
			part.CanCollide = false
			wait( 2.5 )
			part.Transparency = 0.25
			part.CanCollide = true
            debounce = false
        end
    end )
end

The loop gets them all with just this one LocalScript, and the descendant check ensures it was our local player who touched the part before we hide it.

Edit: after seeing the goose chase you were sent on I decided to be nice and swap in your Transparency and CanCollide code for you. Hopefully it’s fairly clear to see how it works.

5 Likes