Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

No Sound Playing When Part Touched? (part 2)

Asked by 5 years ago

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

Log in to vote
1
Answered by 5 years ago

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.

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! SupremeStarfish 21 — 5y
0
Although I would like to add, the part even with can colide off it makes my character go ontop of my lobby. SupremeStarfish 21 — 5y
Ad

Answer this question