I’m facing an issue with my countdown loop – after it turns ‘loading_bar’ elements green, the player can’t move, and the GUI doesn’t hide. Seeking guidance on the problem and a fix. Any insights or solutions appreciated!
video showing error:
localscript:
-- Function to show the frame and hide it after a specified time
local function showAndHideFrame(player)
print("Showing the frame...")
frameToShowHide.Visible = true -- Show the frame
-- Load and play the sound during the countdown
loadSound()
playCountdownSound()
controlPlayerMovement(false, 8)
-- Getting the local player
local player = game.Players.LocalPlayer
-- Getting the PlayerGui
local playerGui = player:FindFirstChild("PlayerGui")
-- Verify that the PlayerGui exists
if playerGui then
-- Now show the new GUI
local loadingGui = playerGui:FindFirstChild("loading_Cooking_UI")
if loadingGui then
loadingGui.Enabled = true
print("loading_Cooking_UI shown.")
else
warn("loading_Cooking_UI not found.")
end
-- Countdown timer loop
for i = countdownDuration, 0, -1 do
if shouldContinueCountdown then
loadingTextButton.Text = "The cooking is " .. i .. " seconds left until finished."
-- Change the color of each bar in loading_Cooking_UI
local loadingGui = playerGui:FindFirstChild("loading_Cooking_UI")
if loadingGui then
for barIndex, bar in ipairs(loadingGui.Frame.loading_bar:GetChildren()) do
if bar:IsA("Frame") then
-- Assuming you have white bars, you can change the color to something else
bar.BackgroundColor3 = Color3.new(0, 1, 0) -- Change to green (adjust as needed)
wait(1)
end
end
else
warn("loading_Cooking_UI not found.")
end
else
break -- Exit the loop if shouldContinueCountdown is false
end
end
-- Wait for 1 second after the loop
wait(1)
-- Now hide the loading_Cooking_UI after the countdown
local loadingGui = playerGui and playerGui:FindFirstChild("loading_Cooking_UI")
if loadingGui then
loadingGui.Enabled = false
print("loading_Cooking_UI hidden.")
else
warn("loading_Cooking_UI not found.")
end
controlPlayerMovement(true, 16)
print("Hiding the frame...")
frameToShowHide.Visible = false -- Hide the frame after the specified time
local player = game.Players.LocalPlayer
if player then
-- Check if cancel button is pressed
if isCancelButtonPressed then
print("Cancel button pressed. Tool not added to the player's backpack.")
controlPlayerMovement(true, 16)
else
-- Add the specific tool to the player's backpack
if specificTool then
print("Adding the specific tool to the player's backpack...")
local toolClone = specificTool:Clone()
toolClone.Parent = player.Backpack
else
warn("Specific tool not found.")
end
-- Reset the cancel button state and the countdown status
isCancelButtonPressed = false
shouldContinueCountdown = true
end
else
warn("Player not found.")
end
end
end