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

Music not playing to all players?

Asked by 5 years ago

I wanted to play a music when an amdinistrator wrote it's name on a textbox and clicked on a button to confirm. But it's not playing to others, but just to me. (I used Test where there are 2 players). I put the music in the workspace. The LocalScript in the Button.

local localgui = game.Players.LocalPlayer.PlayerGui

script.Parent.MouseButton1Click:Connect(function()
    if localgui.GUI.AdminPanel.Text == "!setalarm CB true" then
        game.ReplicatedStorage.CBAlarm:Play()
        game.ReplicatedStorage.CBAlarm.Looped = true
        game.StarterGui.GUI.Main.AlarmsList.ContainmentBreach.TextLabel.Text = "ON"
    end
    if localgui.GUI.AdminPanel.Text == "!setalarm CB false" then
        game.ReplicatedStorage.CBAlarm:Play()
        game.ReplicatedStorage.CBAlarm.Looped = false
        game.StarterGui.GUI.Main.AlarmsList.ContainmentBreach.TextLabel.Text = "OFF"
    end
end)
0
Because an action you do on the client won't replicate to other clients. You should use RemoteEvents Rare_tendo 3000 — 5y
0
remote events needed if you want it be shown to all the other players. :FireServer and stuff like that. https://developer.roblox.com/api-reference/class/RemoteEvent tonyv537 95 — 5y
0
Could anyone write the whole scripts and tell me where to put those scripts? Please I need helpp. Fixer1987 95 — 5y
0
I'll do it sen_trix 31 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

This is not a request site, but I will help you get to what you are looking for.

The issue you are experiencing is that FilteringEnabled is preventing you from playing the audio across all clients. To get around this, you must play the sound from the Server.

This is a good article to get started with RemoteEvents. https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events

After reading this over, you can do something like this:

SERVER SCRIPT

local Event = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
Event.Name = "CBAlarmEvent"

local Sound = game:GetService("ReplicatedStorage"):WaitForChild("CBAlarm")
Event.OnServerEvent:Connect(function(Player, OnOff)
    if OnOff == true then
        Sound:Play() Sound.Looping = true
        game.StarterGui.GUI.Main.AlarmsList.ContainmentBreach.TextLabel.Text = "ON"
        Event:FireAllClients("ON") -- Tell clients to change local text to ON
    else
        Sound:Play() Sound.Looping = false
        game.StarterGui.GUI.Main.AlarmsList.ContainmentBreach.TextLabel.Text = "OFF"
        Event:FireAllClients("OFF") -- Tell clients to change local text to OFF
    end
end)

LOCAL SCRIPT

local localgui = game.Players.LocalPlayer.PlayerGui

script.Parent.MouseButton1Click:Connect(function()
    if localgui.GUI.AdminPanel.Text == "!setalarm CB true" then
        game.ReplicatedStorage:WaitForChild("CBAlarmEvent"):FireClient(true) -- Turn on audio
    end
    if localgui.GUI.AdminPanel.Text == "!setalarm CB false" then
        game.ReplicatedStorage:WaitForChild("CBAlarmEvent"):FireClient(false) -- Turn off audio
    end
end)

game.ReplicatedStorage:WaitForChild("CBAlarmEvent").OnClientEvent:Connect(function(Text)
    localgui.GUI.Main.AlarmsList.ContainmentBreach.TextLabel.Text = Text
end)

This script could use some work and I suggest you continue looking into the article for more info. I did not make it perfect as I want you to learn (this is not a request site), but it should be functional.

If this helped, mark it correct and upvote. Thanks!

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
**The reason why the other players in the server cannot hear the song that your are playing is that the game is filtering enabled [Click here for more info](https://developer.roblox.com/api-reference/property/Workspace/FilteringEnabled) and if the client tries telling the server to do something, the server will ignore it. Obviously we would be limited to what we could do with local scripts so roblox has something called Remote Events and Remote Fuctions. These Events allow the server and the client to communicate with each other.**

What you want to do is to create a remote event in the replicated storage and call it "songEvent". Now create a script in the ServerScriptService and call it "remoteEventScript" inside of it type this:

Server Script

local RemoteEvent = game.ReplicatedStorage.songEvent

RemoteEvent.onServerEvent:Connect(function(player)
    game.ReplicatedStorage.CBAlarm:Play()
end)

Local Script

local localgui = game.Players.LocalPlayer.PlayerGui

script.Parent.MouseButton1Click:Connect(function()
    if localgui.GUI.AdminPanel.Text == "!setalarm CB true" then
        game.ReplicatedStorage.songEvent:FireServer()
        game.StarterGui.GUI.Main.AlarmsList.ContainmentBreach.TextLabel.Text = "ON"
    end
    if localgui.GUI.AdminPanel.Text == "!setalarm CB false" then
        game.ReplicatedStorage.CBAlarm:Play()
        game.ReplicatedStorage.CBAlarm.Looped = false
        game.StarterGui.GUI.Main.AlarmsList.ContainmentBreach.TextLabel.Text = "OFF"
    end
end)
0
I am sorry to say that it isn't working. I agree with your thoughts. But it isn't working and output says nothing. Fixer1987 95 — 5y

Answer this question