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

No Sound Playing When Part Touched? (part 2)

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

1 answer

✓ Accepted answer

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.

2 comments

0

Awesome, you are genius the only changes i needed to make were of course Instancing the ScreenGui and the Frame, but other wise thanks sooo much!

0

Although I would like to add, the part even with can colide off it makes my character go ontop of my lobby.

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