I am currently implementing a system that plays an audio in response to MessagingService:SubscribeAsync().
From a ServerScript, the Remote Event is fired in this code snippet:
if not RunService:IsStudio() then
MessagingService:SubscribeAsync(ADMIN_MESSAGE_TOPIC, function(data)
local message = data.Data
AdminEvent(message)
-- Fire AdminMusicEvent to all players
for _, player in Players:GetPlayers() do
print("Fired")
AdminMusicEvent:FireClient(player, "taco")
end
end)
end
The firing of the event is then listened to in a LocalScript parented to a TextButton in StarterGui in this code snippet:
AdminMusicEvent.OnClientEvent:Connect(function(message)
print(message)
if message == "taco" then
print("In")
musicPlayer:Pause()
AdminMusic:Play()
AdminMusic.Ended:Wait()
AdminMusic:Stop()
musicPlayer:Resume()
end
end)
When tested in a Roblox server (not Studio), “AdminMusicEvent:FireClient(player, “taco”)” never gets fired. When I run this line of code outside of the code block from the ServerScript, it runs perfectly fine. What is causing this issue?
Have you checked what is broadcasting the message you are subscribing to?
(did it sucessfully broadcast the topic ADMIN_MESSAGE_TOPIC?)
also, if you want to fire to all clients, there’s a function for that
I am not following… so a seperate function sucessfully subscribed to this topic?
Have you tried adding a print statement to see wether this function recieved the message?
It should be that you can have any number of subscribe async to the same topic…
It could be that your code eventually works, but you have to wait 50*1.75 seconds, or over a minute and a half. (comment out the for loop and see what happens please)
The line with TacoEvent should become coroutine.wrap(TacoEvent)()
Code by default runs sequentially? If I tell you to walk to the door and open it, you can’t open the door while walking toward it? coroutines make code run “parallel”, unlike multi-threading, it isn’t real parallel, but for all intents and purposes it is good enough.