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

Music Works Perfectly in the Studio, but not in the Game. Any Idea on How to Fix This?

I am trying to play music in specific areas by placing a block that is invisible and players cannot collide with it, so when the players "hit" that block, then music will start playing. I placed a script within the part for the music, but the problem is that in Roblox Studio, the music will play, but as I test it in game, the music does not play at all. Any idea on how to fix this?

script.Parent.Touched:connect(function(hit)
    if hit.Parent:WaitForChild('Humanoid') then
        local player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
        local playergui = player:WaitForChild('PlayerGui')
        local sound3 = playergui:WaitForChild('Sound3')
 
        sound3.Volume = 1
        sound3:Play()
    end
 end)
script.Parent.TouchEnded:connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid')then
game.Players[hit.Parent.Name].PlayerGui.Sound3.Volume = 0
end
end)

2 comments

0

Is your game filtering enabled?

0

No

2 answers

You can try,

debounce = false

script.Parent.Touched:connect(function(hit)
if not debounce then
debounce = true
if(hit.Parent:FindFirstChild("Humanoid")~=nil)then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local sound = script.Parent.Sound:Clone()
sound.Parent = player.PlayerGui
sound:Play()
wait(30)
end
debounce = false
end
end)

Insert this into part, make sure you also insert sound.

If this won't work, try exiting out the part and touch it again. But if it doesn't, this may not be the answer.

Pretty sure this will fix it. You should preload the sound, by doing the following.

local SoundId = 123456 --Insert sound Id here.
game:GetService("ContentProvider"):Preload(SoundId)

--insert the rest of your script here

2 comments

0

This just made it not work completely :(

0

Does the sound ID even exist?

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