I’m currently trying to get the player count for a different place using MessagingService, however, I’m getting the error “attempt to index nil or with number”. Here’s my code:
Local Script:
local invoke = game.ReplicatedStorage.Functions.GetPlayersOnline:InvokeServer(placeid.Value)
script.Parent.Text = invoke[1].." players online"
Event Script:
functions.GetPlayersOnline.OnServerInvoke = function(player, place_id)
local success, con = pcall(function()
MessagingService:SubscribeAsync("JoinEvent", function(message)
print("PlayerCount: "..message[1])
print("GameID: "..message[2])
return message[1], message[2]
end)
end)
end
Script in different place:
Players.PlayerAdded:Connect(function(player)
local success, result = pcall(function()
local message = {#PlayerCount, game.PlaceId}
MessagingService:PublishAsync("JoinEvent", message)
end)
if not success then
print(result)
end
end)
Any idea how to solve this? If so, please post it below.
functions.GetPlayersOnline.OnServerInvoke = function(player, place_id)
local success, con = pcall(function()
MessagingService:SubscribeAsync(“JoinEvent”, function(message)
print("PlayerCount: "…message[type any number here])
print("GameID: "…message[put function 2])
Players.PlayerAdded:Connect(function(player)
local success, result = pcall(function()
local message = {#PlayerCount, game.PlaceId}
MessagingService:Publish(fuction(“JoinEvent”, message)
end)
if not success then
print(result)
end
end)
[/quote]
put in ScriptStorage. and add events to ReplicatedStorage.