Reputation: 31
I'm a tad stuck with local music playing on my Roblox game.
I've got a setup on my game where a script inserts five sound files into a player's GUI. When a sever is made these sounds do make it to the players gui.
To play the sounds there are parts setup that check for collisions with players and when they detect a player they will start one of the five sounds in the player's GUI.
This is what the code in one of the parts looks like:
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
if game.Players[hit.Parent.Name].PlayerGui.Sound2.TimePosition < 1 then
game.Players[hit.Parent.Name].PlayerGui.Sound2.Volume = 1
game.Players[hit.Parent.Name].PlayerGui.Sound2:Play()
game.Players[hit.Parent.Name].PlayerGui.Sound1:Stop()
game.Players[hit.Parent.Name].PlayerGui.Sound4:Stop()
game.Players[hit.Parent.Name].PlayerGui.Sound3:Stop()
game.Players[hit.Parent.Name].PlayerGui.Sound5:Stop()
end
end
end)
This script does detect players just fine as I have tested it. The system does work in the Roblox Studio testing area however when a server is launched with it none of the sounds are played.
The server does in fact set the sounds to playing and they appear as playing on the client side from the server side however the client side does not see them as playing and they do not play.
I do have filtering enabled turned on but this shouldn't effect it...
Upvotes: 2
Views: 4503
Reputation: 1
I recently ran into this issue while making a music player. It ended up being the silliest thing and had everything to do with FE. My player worked in Test Studio, but gave me a whole laundry list of error codes that I was able to fix simply by changing the script to a local script. Literally all the same code worked as it did in studio but client side. It took me a entire day of head scratching and wiki searching to figure out my mistake. FE was initially a nightmare for me, but I have come to love the security it provides my games. :)
Upvotes: 0
Reputation: 31
Filtering enabled is the reason this doesn't work.
To solve this you can use a RemoteEvent located in the ReplicatedStorage of your game.
The sounds must be placed in the StarterGUI and there should be a localscript with this code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:WaitForChild("REMOTE EVENT NAME")
script.Parent.Sound2.Playing = true
local function onNewPlayerFired(sound)
script.Parent.Sound1.Playing = false
script.Parent.Sound2.Playing = false
script.Parent.Sound3.Playing = false
script.Parent.Sound4.Playing = false
script.Parent.Sound5.Playing = false
script.Parent[sound].Playing = true
end
event.OnClientEvent:Connect(onNewPlayerFired)
and in the part for each sound trigger part there should be this code:
local debounce = false
script.Parent.Touched:connect(function(hit)
if debounce == true then return end
debounce = true
if hit.Parent:FindFirstChild('Humanoid') then
local plr = game.Players:FindFirstChild(hit.Parent.Name)
game.ReplicatedStorage.REMOTE EVENT NAME:FireClient(plr,"SOUND NAME")
end
wait(2)
debounce = false
end)
Upvotes: 0
Reputation:
A way to do that is parenting the sounds to PlayerGui (I think you needed a ScreenGui) and then :Play() them.
Upvotes: 1
Reputation: 63
I believe it is something quite simple. I think it is a function of the SoundService. Correct me if this doesnt work, but i believe this is it
soundobj = game.Players[hit.Parent.Name].PlayerGui.Sound2
game:GetService('SoundService'):PlayLocalSound(soundobj)
see https://wiki.roblox.com/index.php?title=API:Class/SoundService/PlayLocalSound for more info
Upvotes: 1