Having problems with sound script

I am having problem with a sound script that is meant to play 2 different at different times.

when I load into the game, it loads sound2 properly but doesn’t load sound at all.

local sound = Instance.new("Sound") --durdurdurddurdurdafsaaa

sound.Name = "Sound2"
sound.SoundId = "http://www.roblox.com/asset/?id=1845785305" --Change The Number By your Music ID.
sound.Volume = 10 --Volume Change It If You Want.
sound.Pitch = 1.2 --Speed of Playback.
sound.Looped = true --If Chnage True By False The Song Will Play 1 Time.
sound.archivable = false

sound.Parent = game.Workspace

local sound2 = Instance.new("Sound") --lobby

sound2.Name = "Sound"
sound2.SoundId = "http://www.roblox.com/asset/?id=1839276018" --Change The Number By your Music ID.
sound2.Volume = 1 --Volume Change It If You Want.
sound2.Pitch = 1.2 --Speed of Playback.
sound2.Looped = true --If Chnage True By False The Song Will Play 1 Time.
sound2.archivable = false

sound2.Parent = game.Workspace

local value = game.ReplicatedStorage.RoundOn.Value

wait()

local function Sound2()
	if value == false then
		if sound2.IsPlaying == false then
			sound2:Play()
			if sound.IsPlaying then
				sound:Stop()
			end
		end
	end
end

local function Sound()
	if value == true then
		if sound.IsPlaying == false then
			sound:Play()
			if sound2.IsPlaying then
				sound2:Stop()
			end
		end
	end
end

while true do
	
	Sound2()
	Sound()
	
	wait(0.2)
end

Have you tried loading the sounds with ContentProvider?

Problem lies here

local RoundOn = game.ReplicatedStorage.RoundOn.Value

When you define it like this, it’ll only contain RoundOn’s value at that specific moment of time and subsequent changes to RoundOn’s value won’t update the variable

Instead,

local RoundOn = game.ReplicatedStorage.RoundOn

-- RoundOn.Value == true
-- RoundOn.Value == false

Also, I recommend you use connections instead of a while loop for this

-- Something like this
local RoundOn = game.ReplicatedStorage.RoundOn

local function OnChanged(value)
     if value == true then
       -- 
    elseif value == false then
       --
    end
end

OnChanged(RoundOn.Value)
RoundOn.Changed:Connect(OnChanged)

This avoids unnecessary execution of code

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.