Scripting Help | Remote Event + Subscribe Async

Hey Everyone!

Im trying to create a remote event that runs a subscribe async, but it work work. Here is my script!

function runSCWin()
	game:GetService("MessagingService"):PublishAsync("SCWin",{m="Hi!"})
end

game.ReplicatedStorage.Win.OnServerEvent:Connect(function(sc)
    if sc == true then
		runSCWin()
	end
end)

game:GetService("MessagingService"):SubscribeAsync('SCWin',function(mdata)
	local message = mdata.Data.m
	if message then
		print("Message Recieved! "..message)
	end
end)

Notes: Script is inside SERVERSCRIPTSERVICE.
Runs whenever a player beats a obby in a game im making.

1 Like

When you listen for RemoteEvents to be fired, it returns the player who fired it as the first argument and whatever was passed by the client. That means you are checking if a Player instance is equal to true.

Try replacing that section with this:

game.ReplicatedStorage.Win.OnServerEvent:Connect(function(player, sc)
    if sc == true then
		runSCWin()
	end
end)
2 Likes

Still does not work. it runs however it doesnt print the message itself.

Iā€™m not sure what you mean. What is it printing? The only use of print in your script is to signify that the message was sent successfully and received by other servers (which should indicate it is working as intended).

Have you confirmed that the server is successful with the PublishAysnc() request? You can either wrap it in a pcall or just add a print line below the request.

Are you sending messages across servers or just 1 server?

Across All Servers. (ignore this, making my message longer so it will send.)

Yes, i tested it and it works IF called directly from the server, otherwise it wont print.

The problem has to be with the remote being called, I pasted your code in a blank place along with a local script that calls the event instantly; it works.

1 Like

I accually just realised my mistake. The remote couldnt run BECAUSE a value was set to false when it was suppost to be set to true. Thank you for your help anyways however.