Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make it wait 10 seconds before it plays the music?

local plr = game.Players.LocalPlayer
local char
local torso

local container = game.ReplicatedStorage:WaitForChild("CinderingBGM")
local settings = require(container:WaitForChild("Settings"))
local musicfolder = container:WaitForChild("MusicFolder")
local globalfolder = musicfolder:WaitForChild("GlobalMusic")
local zonesfolder = musicfolder:WaitForChild("MusicZones")
local servercount = container:WaitForChild("ObjectCount").Value

function GetMatchingCount() --objects can take some time to actually replicate to the client. make sure that the client sees the correct # of objects in the music folder before initializing the rest of the script
	local count = 0
	local function recurse(instance)
		for _,v in pairs(instance:GetChildren()) do
			count = count + 1
			recurse(v)
		end
	end
	recurse(musicfolder)
	if count == servercount then return true end
end

while not GetMatchingCount() do
	wait(.5)
end


function IsCleanRotation(v3values) --check to see whether the rotation is at clean 90 degree increments so we can use the more simplistic calculations for it
	for _,v in pairs(v3values) do
		if not (v%90 <= 0.01 or v%90 >= 89.99) then --why not just check for (v%90 == 0)? because rotations can suffer from floating point inaccuracies
			return false
		end
	end
	return true
end

1 comment

0

Use the wait function, for example, wait(10)

2 answers

✓ Accepted answer
wait(10)
local plr = game.Players.LocalPlayer
local char
local torso

local container = game.ReplicatedStorage:WaitForChild("CinderingBGM")
local settings = require(container:WaitForChild("Settings"))
local musicfolder = container:WaitForChild("MusicFolder")
local globalfolder = musicfolder:WaitForChild("GlobalMusic")
local zonesfolder = musicfolder:WaitForChild("MusicZones")
local servercount = container:WaitForChild("ObjectCount").Value

function GetMatchingCount() --objects can take some time to actually replicate to the client. make sure that the client sees the correct # of objects in the music folder before initializing the rest of the script
    local count = 0
    local function recurse(instance)
        for _,v in pairs(instance:GetChildren()) do
            count = count + 1
            recurse(v)
        end
    end
    recurse(musicfolder)
    if count == servercount then return true end
end

while not GetMatchingCount() do
    wait(.5)
end


function IsCleanRotation(v3values) --check to see whether the rotation is at clean 90 degree increments so we can use the more simplistic calculations for it
    for _,v in pairs(v3values) do
        if not (v%90 <= 0.01 or v%90 >= 89.99) then --why not just check for (v%90 == 0)? because rotations can suffer from floating point inaccuracies
            return false
        end
    end
    return true
end

Put in wait (10) before the place where the music starts playing

This discussion is preserved as it was. New answers, comments, and votes are closed.