I’m just fooling around with functions at the moment. I wanted this script to change a part in the model to bright red, then to be parented to Workspace so that it would not be part of the calculation for the next random part selected. Eventually this would continue until all of the parts were red and parented to the workspace. However, instead, almost all of the parts are turned red on the first part touched.
local debounce = false
local release = game.Workspace.Release
local releaseParts = release:GetChildren()
local function openGuiWithParts(part, object)
if not debounce then
debounce = true
if object:FindFirstChild("Humanoid")then
local randomPart = releaseParts[math.random(1, #releaseParts)]
randomPart.BrickColor = BrickColor.new("Bright red")
randomPart.Parent = game.Workspace
end
debounce = false
end
end
for i, v in pairs(releaseParts)do
v.Touched:Connect(function(part)
if not debounce then
openGuiWithParts(v, part.Parent)
end
end)
end
The name of the function is a bit misleading, I haven’t started working with the GUI for the moment, but I wanted to make it appear once all four parts are Bright red.
If you want to remove a part from the calculation, make sure you reset the value of releaseParts after parenting a part to the workspace. The table will still contain all parts that were children of release when you set the value of releaseParts.
As for all parts turning red immediately, add a wait(x), where x is some amount of time, before you set debounce back to false.
@itsLevande How would I go about resetting releaseParts? I tried GettingChildren again after parenting to workspace but that didn’t seem to work.
local debounce = false
local release = game.Workspace.Release
local releaseParts = release:GetChildren()
local function openGuiWithParts(part, object)
if not debounce then
debounce = true
if object:FindFirstChild("Humanoid")then
local randomPart = releaseParts[math.random(1, #releaseParts)]
randomPart.BrickColor = BrickColor.new("Bright red")
randomPart.Parent = game.Workspace
release:GetChildren()
end
wait(1)
debounce = false
end
end
for i, v in pairs(releaseParts)do
v.Touched:Connect(function(part)
if not debounce then
openGuiWithParts(v, part.Parent)
end
end)
end