Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago

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)


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 jediplocoon 877 — 4y
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" jediplocoon 877 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Ad

Answer this question