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

How can I make parts appear/disappear using a custom command?

Asked by 4 years ago
Edited 4 years ago

I'm looking for a way to make a few parts appear after using a custom command, then disappear after using the command again. I'm relatively new to lua and roblox game development so any sort of advice would help. Thanks.

Here's what I have for the command part, not sure on what to put after the 'then'.

function onChatted(msg, speaker)
    local source = string.lower(speaker.Name)
    msg = string.lower(msg)
    if msg == "!show" then

    end
end

2 answers

Log in to vote
0
Answered by
3132750 45
4 years ago

You would have to make an array with all the parts you want to appear and disappear. Then, a for loop to set transparency and canCollide.

Here is what the code should look like

--this defines the list of parts you want to hide and show
local parts = {script.Parent.part1,script.Parent.part2,script.Parent.part3}
--this loop goes through the parts in the list and hides them
for _, part in ipairs(parts) do
    part.Transparency = 1
    parts.canCollide = false
end
--this waits 5 secounds before it shows them again
wait(5)
--this loop goes through the parts in the list and shows them
for _, part in ipairs(parts) do
    part.Transparency = 0
    parts.canCollide = true
end
Ad
Log in to vote
0
Answered by 4 years ago

You could use the Destroy() function say whatever your're trying to do to cause the brick to break try after the then


Part:Destroy() else Part = Instance.new("Part")

Answer this question