So I’m making a script that changes the brick color of a random part in the model to Bright red. The part will then be parented to the workspace. When all parts are in the workspace and bright red I would like the GUI to pop up. So far the bricks turn red and are parented to the workspace but the gui is not popping up.
local debounce = false
local release = game.Workspace.Release
local releaseParts = release:GetChildren()
local Players = game:GetService("Players")
local allPlayers = Players:GetPlayers()
local function colorBricksRed(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
releaseParts = release:GetChildren()
end
wait(1)
debounce = false
end
end
local function openGuiWithParts()
for i, v in pairs(allPlayers) do
v.PlayerGui:WaitForChild("ScreenGui")
v.PlayerGui.ScreenGui.Enabled = true
end
end
for i, v in pairs(releaseParts)do
v.Touched:Connect(function(part)
if not debounce then
colorBricksRed(v, part.Parent)
end
end)
end
while true do
if game.Workspace:FindFirstChild("Part1")and game.Workspace.Part1.BrickColor == ("Bright red") then
if game.Workspace:FindFirstChild("Part2")and game.Workspace.Part2.BrickColor == ("Bright red") then
if game.Workspace:FindFirstChild("Part3")and game.Workspace.Part3.BrickColor == ("Bright red") then
if game.Workspace:FindFirstChild("Part4")and game.Workspace.Part4.BrickColor == ("Bright red") then
openGuiWithParts()
end
end
end
end
wait(1)
end
What @NineFineMuscadines said, it won’t go past the initial while true do loop. I’m not sure why that is though, Part1 does eventually get added to the workspace after it becomes red?
Nevermind what I just said aaa My guess is that you’re only getting the Players once, either that or 1 of your conditional if statements aren’t equal to the BrickColor it’s supposed to be
local debounce = false
local release = game.Workspace.Release
local releaseParts = release:GetChildren()
local Players = game:GetService("Players")
local allPlayers = Players:GetPlayers()
local function colorBricksRed(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
releaseParts = 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
colorBricksRed(v, part.Parent)
end
end)
end
while true do
if game.Workspace:FindFirstChild("Part1")and game.Workspace.Part1.BrickColor == BrickColor.new("Bright red") then
if game.Workspace:FindFirstChild("Part2")and game.Workspace.Part2.BrickColor == BrickColor.new("Bright red") then
if game.Workspace:FindFirstChild("Part3")and game.Workspace.Part3.BrickColor == BrickColor.new("Bright red") then
if game.Workspace:FindFirstChild("Part4")and game.Workspace.Part4.BrickColor == BrickColor.new("Bright red") then
for i, v in pairs(allPlayers)do
if v.PlayerGui.ScreenGui.Enabled == false then
v.Player.ScreenGui.Enabled = true
elseif v.PlayerGui.ScreenGui.Enabled == true then
break
end
end
end
end
end
end
wait(1)
end
for i, v in pairs(game.Players:GetPlayers()) do
if v.PlayerGui.ScreenGui.Enabled == false then
v.Player.ScreenGui.Enabled = true
elseif v.PlayerGui.ScreenGui.Enabled == true then
break
end
end
I’ll actually explain it
So, from what I understand, turns out the Script actually starts to already get all the Players when it first runs, but since you defined your allplayers variable at the start, my guess is that the script already detects no players when it first runs inside the server (Since it runs too quickly that it doesn’t detect you while you hit Play)
You can also try out this code for future reference I guess inside the workspace:
local Players = #game.Players:GetPlayers()
print(Players)
--Expected Output: 0