Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make this part invisible and then visible again with code?

I have a script that allows a player to click on an object and then receive the clone of that object from lighting. I want to make it seem like that item will "respawn" after a set amount of time. Previously I just destroyed the part but I want other players to be able to pick it up again after a cooldown but I'm not sure how to do that.

local Part = script.Parent

Toolname = "SCP_LEVEL1" 
	 
	function boop(Player)
	    if not Player.Backpack:FindFirstChild("SCP_LEVEL1") then
	        local Tool = game.Lighting.SCP_LEVEL1:Clone()
       Tool.Parent = Player.Backpack
	wait (5)
-- Not sure what to put here to make it invisible then visible again
	    end
	end
	script.Parent.ClickDetector.MouseClick:connect(boop)


2 comments

0

just use transparency to make it go invisible, "Part.Transparency = 1" to make it go invisible, then "Part.Transparency = 0" to make it appear again, sorry if this is incorrect I'm fairly new to coding myself

0

also if you want to make it so they can only pick it up after a certain amount of time, look into a thing called "debounce"

1 answer

You would change the transparency, and since you're using a clickdetector, you'd also set the maxactivationdistance to 0, so it won't appear like you can click it while it's respawning. Lastly, you'd need a "debounce" so your event doesn't fire multiple times while it's respawning.


local Part = script.Parent
db = false

Toolname = "SCP_LEVEL1" 

    function boop(Player)
        if not Player.Backpack:FindFirstChild("SCP_LEVEL1") and not db then 
	
		db = true
		local Tool = game.Lighting.SCP_LEVEL1:Clone()
		Tool.Parent = Player.Backpack
		Part.Transparency = 1
		Part.ClickDetector.MaxActivationDistance = 0
		wait(5)
		Part.Transparency = 0
		Part.ClickDetector.MaxActivationDistance = 12
		db = false
        end
    end

    Part.ClickDetector.MouseClick:Connect(boop)

You can change the 12 in the MaxActivationDistance to whatever you want as well.

This discussion is preserved as it was. New answers, comments, and votes are closed.