Issue with Remote Event

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?

Thanks :slight_smile:

1 Like

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 believe I have a separate block of code that also reaponds to the same subscription. I believe that you can only use this once, is thia the issue?

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…

I have two different code segements that are subacribed to the same topic in one script. Could this be causing problems?

I highly doubt this is what causes the problem, however, you should check wether the broadcast async is firing properly.

The PublishAsync?

Chars :DDDDDDD

1 Like

can you print command just to make sure it works as expected? thanks… (can’t access studio rn sorry)

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)()

Is the code firing sequentially because of the two SubscribeAsyncs?

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.

1 Like

That worked, thanks!

I somehow missed the call to that function directly in front of the SubscribeAsync(). -_-

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.