Just over a month ago, I posted a topic about how I couldn’t get my music script to work. I was making a script that would play a song when you stepped on a brick and would stop that song and play a new one when you stepped on a different brick. With some help, I got the script working perfectly. The link to the first post is below.
I returned to that script today so I could implement it into my game, only to find that it was broken. The two bricks and the script are in a separate testing game. One of the songs would not play at all in Studio when I clicked the preview button (it must have been deleted) and the other song would. Neither brick, however, would play the song it was supposed to play when I touched them in playtest.
I took the songid from the working song and put it into the actual game, and the preview wouldn’t even work there. I don’t have the slightest idea why this glitch is happening, and it’s annoying the crap out of me because I just fixed it the other week when it broke.
local sound = script.Parent.bruh
local partsound = workspace.Red.san
local part = script.Parent
local red = workspace.Red
local Debounce1 = false
local Debounce2 = false
part.Touched:Connect(function(Object)
local plr = game.Players:GetPlayerFromCharacter(Object.Parent)
if plr then
if not Debounce1 then
Debounce1 = true
red.Transparency = 0
part.Transparency = 1
sound:Play()
partsound:Stop()
Debounce2 = false
end
end
end)
red.Touched:Connect(function(Hit)
local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
if plr then
if not Debounce2 then
Debounce2 = true
part.Transparency = 0
red.Transparency = 1
sound:Stop()
partsound:Play()
Debounce1 = false
end
end
end)
It works with some sounds. However, in the actual game (not the testing place) even those don’t work. I’m going to the gym rn, so I’ll continue debugging in about 2 hours.
local Folder = script.Parent
local P1 = Folder:FindFirstChild("Red")
local P2 = Folder:FindFirstChild("Black")
local S1 = P1:FindFirstChildOfClass("Sound")
local S2 = P2:FindFirstChildOfClass("Sound")
local Switch = true
local function DoSwitch(Hit, P)
local Plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
if not Plr then return end
if P == P1 and Switch then
Switch = false
P1.Transparency = 1
P2.Transparency = 0
S1:Stop()
S2:Play()
elseif P == P2 and not Switch then
Switch = true
P1.Transparency = 0
P2.Transparency = 1
S1:Play()
S2:Stop()
end
end
P1.Touched:Connect(function(H) DoSwitch(H, P1) end)
P2.Touched:Connect(function(H) DoSwitch(H, P2) end)
If the sounds are incorrect then simply change: S1 to S2 or S2 to S1.
I can’t test to see if that script works. For some reason, no matter what song I insert into my sound value, roblox won’t play it. I’ve tried about 15 songs at this point.
i had the same problem of songs not loading in the actual games, what worked for me was to preload the sounds before asking them to :Play(), for this i used the ContentProvider service