#need help with script working after my character has fully loaded in and to help me with the timing

12 messages · Page 1 of 1 (latest)

tiny stag
#

i need help with my scripts and would like it to start working after my character has fully loaded in to the game and to help me with the timing of two scripts which this script is located in workspace - barrier-script
first script

local barrier = nil

local function initializeBarrier()
barrier = workspace:FindFirstChild("barrier") -- Find the barrier part in the Workspace

if barrier then
    wait(41) -- Wait for 30 seconds

    while true do
        barrier.CanCollide = false -- Enable CanCollide after 30 seconds
        barrier.Transparency = 1 -- Set Transparency to 0.6 after 30 seconds

        wait(120) -- Wait for an additional 2 minutes (120 seconds)

        barrier.Transparency = 0.6 -- Set Transparency to 0 after 2 minutes
        barrier.CanCollide = true -- Initially set CanCollide to false

        -- Optionally, you can reset the CanCollide property to its original state at this point
        -- barrier.CanCollide = <original CanCollide value>
    end
else
    error("Could not find the 'barrier' part in Workspace.")
end

end

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(initializeBarrier)
end)

-- Check if a player is already in the game
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
initializeBarrier()
break
end
end

#

second script
and the next script is located in workspace- barrier- surfacegui- script and in the surface gui there is a textlabel "countdownLabel"

local surfaceGui = script.Parent
local countdownLabel = surfaceGui:WaitForChild("CountdownLabel")

local barrierWaitTime = 41 -- Time to wait before enabling the barrier in seconds
local barrierDuration = 120 -- Duration of the barrier in seconds

while true do
local startTime = os.time()
local endTime = startTime + barrierWaitTime

while true do
    local currentTime = os.time()
    local remainingSeconds = math.max(0, endTime - currentTime)
    countdownLabel.Text = tostring(remainingSeconds) .. "s"

    if currentTime >= endTime then
        break
    end

    wait(1)
end

countdownLabel.Text = ""
wait(barrierDuration)

end

and would like for these two scripts for it to be 30 seconds for the count down then disappear for 2 mins and be in a looped while being linked with the other script timing for the cancolide to be on for 30 secs and then be turned off for 2 mins and be in a loop. i put 41 seconds because it was taking 11 seconds for my character to fully load in to the game

#

need help please

#

i got a part, using it as a barrier and would like a surfacegui on it saying get ready to start and with a 30 sec countdown and then i would like the barrier to disapper then appear again after 2 mins with the 30 sec countdown and would like this in a loop

#

i got two scripts one located inside the barrier part for the barrier to disappear after 30 sec but needs an extra 11 seconds because the scripts start when i click play game and not when i fully load in

blissful sierraBOT
#

studio** You are now Level 3! **studio

tiny stag
#

and the other script located in side the surface gui, i set it 30 seconds but when i play game i see that starts on 17 seconds but after it because of the loop it goes to 30 seconds

#

what like a screen load up ?

#

thanks

#

local player = game.Players.LocalPlayer

local function onCharacterAdded(character)
-- Player's character has loaded
print("Player's character has loaded:", character.Name)
-- Perform actions after the player's character has loaded
end

if player.Character then
-- Player's character is already available
onCharacterAdded(player.Character)
end

player.CharacterAdded:Connect(onCharacterAdded)
local surfaceGui = script.Parent
local countdownLabel = surfaceGui:WaitForChild("CountdownLabel")

local barrierWaitTime = 41 -- Time to wait before enabling the barrier in seconds
local barrierDuration = 120 -- Duration of the barrier in seconds

while true do
local startTime = os.time()
local endTime = startTime + barrierWaitTime

while true do
    local currentTime = os.time()
    local remainingSeconds = math.max(0, endTime - currentTime)
    countdownLabel.Text = tostring(remainingSeconds) .. "s"

    if currentTime >= endTime then
        break
    end

    wait(1)
end

countdownLabel.Text = ""
wait(barrierDuration)

end

#

i added it to the script the timer stoped working