Hello, I am trying to make a new minigame and in this minigame there is going to lots of parts that I am hoping when someone steps on them the block turns transparent and can collide becomes false. I just need help with how I would make a script so that the script would look for all of the parts called disappearingPart that are in a group called MiniGame.
1 Like
local Folder = worskapce.MiniGame
for i,v in pairs(Folder:GetChildren()) do
if (v:IsA("Part") and (v.Name == "disappearingPart") then
end
end
1 Like
Make sure workspace is spelled correctly or script will halt.
3 Likes
local PartsFolder = game.Workspace:FindFirstChild("") -- The folder the parts will be in
local function touchEvent(hit) -- The function that will run when a character touches the part
if not hit.Parent:FindFirstChild("Humanoid") then return end -- Checking if the character contains a Humanoid instance
part.Transparency = 1 -- Setting the transparency
part.CanCollide = false -- Setting the cancollide
end
for _, part in pairs(PartsFolder:GetChildren()) do -- Going through all the parts in the folder
if (part:IsA("Part") then -- Checking if they are a Part instance
part.Touched:Connect(touchEvent) -- Connecting the .Touched event to the function above
end
end
2 Likes
-- Define where the MiniGame folder is
local MiniGame = workspace.MiniGame
-- Go through the folder
for i, v in pairs(MiniGame:GetChildren()) do
if (v:IsA("BasePart")) or (v:IsA("Part")) and (v.Name == "disappearingPart") then
--Put your code here.
-- This will loop through each part in the folder, so reference the part as 'v'.
end
end
1 Like
for _, Part in workspace.MiniGame:GetChildren() do
if Part.Name == 'disappearingPart' then
local debounce = false
Part.Touched:Connect(function(otherPart)
if otherPart and game.Players:GetPlayerFromCharacter(otherPart.Parent) and not debounce then
task.wait(0.3) -- Seconds before the part disappears
Part.Transparency = 1
Part.CanCollide = false
debounce = true
task.wait(2.5) -- Seconds before the part reappears
debounce = false
Part.Transparency = 0
Part.CanCollide = true
end
end)
end
end
Whenever the disappearing part is touched, it will check if the part that touched it is part of a player and debounce is currently set to false, then it waits 0.3 seconds before making it invisible and not collidable and sets debounce to true, then it waits 2.5 seconds before setting debounce to false and making it visible and collidable.
1 Like