local sound = game.SoundService.LobbyAmbience
game:GetService("ContentProvider"):PreloadAsync({sound})
game.ReplicatedStorage.RemoteEventPressAnyKeyToStartTheAmbience.OnServerEvent:Connect(function(player)
sound:Play()
end)
This is localscript :
local GUI = script.Parent
local userinputservice = game:GetService("UserInputService")
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEventPressAnyKeyToStartTheAmbience")
userinputservice.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("Player has pressed keyboard")
Remote:FireServer()
end
end)
So there are two identical local scripts like that but they both are connected to different server scripts. One does the GUI collapse when any button has been pressed and the other one when a button has been pressed, turns on the ambience. GUI collapses all right with everything working except the ambience is not playing and there are no errors or warnings (yes I checked my volume too).
local debounce = false
local sound = game.SoundService.LobbyAmbience
game:GetService("ContentProvider"):PreloadAsync({sound})
game.ReplicatedStorage.RemoteEventPressAnyKeyToStartTheAmbience.OnServerEvent:Connect(function(player)
if debounce == false then
debounce = true
sound:Play()
sound.Ended:Wait()
debounce = false
end
end)
local debounce = false
local sound = game.SoundService.LobbyAmbience
game:GetService("ContentProvider"):PreloadAsync({sound})
print(1)
game.ReplicatedStorage.RemoteEventPressAnyKeyToStartTheAmbience.OnServerEvent:Connect(function(player)
if debounce == false then
debounce = true
sound:Play()
print(2)
sound.Ended:Wait()
debounce = false
end
end)
local GUI = script.Parent
local userinputservice = game:GetService("UserInputService")
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEventPressAnyKeyToStartTheAmbience")
print(3)
userinputservice.InputBegan:Connect(function(input, gameProcessedEvent)
print(4)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("Player has pressed keyboard")
Remote:FireServer()
end
end)
There is no need for you to play the sound on server, and by the time the player will press a key sound should already load, so why not move everything over to client and use SoundService:PlayLocalSound() instead?
Its supposed to still print 2,3,4 since I only told you to change the LobbyAmbience and the ServerScript, both of which doesnt affect the localscript. Unless you undid your changes to the localscript? Make sure your localscript is in StarterGui, and the LobbyAmbience is in the Workspace.