I have a PlayerAdded
connection that detects when the player joins the game, and then follows with an attempt to subscribe to a message topic. Ideally this is to make global messages happen, and for the most part it seems to work, but sometimes it doesn’t. Usually the player either has to rejoin, or wait for the server to restart entirely. However…
plrs.PlayerAdded:Connect(function(plr)
print("Ran for player ",plr)
plr.CharacterAdded:Connect(function(c)
local curTower = Instance.new("StringValue")
curTower.Parent = c
curTower.Name = "CurTower"
end)
local subSuccess, subConnection = pcall(function()
print("Attempting connection.")
return msgs:SubscribeAsync(globalMsgTopic, function(message)
print("Received message.")
serverMessage:FireClient(plr, message.Data)
end)
end)
if subSuccess then
print("Connecting for ", plr, " successful.")
plr.AncestryChanged:Connect(function()
subConnection:Disconnect()
end)
else
warn("Player not connecting.")
end
end)
This is mostly ripped from a developer guide on the function. But despite the connection not working for one of the players, the warning does NOT send. I thought it might just be the PlayerAdded
connection not working, but it ALWAYS does. I’ve been trying to fix this for a few hours but nothing fruitful has come up, including looping the SubscribeAsync attempt until successful.
Note, this was tested with my own account and an alt on a separate device. There was a duplicate place with the exact same scripts, and the global message definitely worked, but the issue still happened even if the players are in the same place.