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