Okay, so some of you people have seen part 1 and know the following: Its a local script, i'm trying to only make it play to certain players, and the sound is in PlayerGui. What I did not mention is my goal is to make the sound play SPECIFICALLY only to the players Touching the LobbyMusicPart. Heres the script. Oh! And no errors! Just audio won't play...
local LobbyMusicPart = game.Workspace.LobbyMusicPart
local playergui = game.Players.LocalPlayer:WaitForChild(“PlayerGui”)
local LobbyMusic = Instance.new(“Sound”)
LobbyMusic.Name = “LobbyMusic”
LobbyMusic.Parent = playergui
LobbyMusic.SoundId = “rbxassetid://2458556355”
if LobbyMusicPart.Touched == true then
LobbyMusic.Playing = true
else
LobbyMusic.Playing = false
LobbyMusic.TimePosition = 0
end
First of all, you're trying to play the sound in the PlayerGui.
You can't do that. PlayerGui
is just like a storage for the rest of ScreenGui
's and Frames
. You would need to parent the sound to a Frame that is located inside a ScreenGui in the PlayerGui.
Let me fix up the code for you, because there are just simple mistakes.
local LobbyMusicPart = game.Workspace.LobbyMusicPart local playergui = game.Players.LocalPlayer:WaitForChild(“PlayerGui”) local LobbyMusic = Instance.new(“Sound”) LobbyMusic.Name = "LobbyMusic" LobbyMusic.Parent = playergui:WaitForChild("ScreenGui").Frame -- You need to obviously create these, feel free to change the names, obvs. LobbyMusic.SoundId = "http://www.roblox.com/asset/?id=2458556355 -- Used another method for getting an asset. LobbyMusicPart.Touched:Connect(function(hit) -- This is a function that runs if a part is touched. if hit.Parent:FindFirstChild("Humanoid") then -- Checks if the touched part is a player. LobbyMusic:Play() end end) LobbyMusicPart.TouchEnded:Connect(function(hit) -- This is a function that runs when a part stops touching the music part. if hit.Parent:FindFirstChild("Humanoid") then LobbyMusic.Playing = false end end)
Hope this helps.