MessagingService: "Attempt to index nil with 'Data' "

Textbox local

local Player = game.Players.LocalPlayer
local Remote = script:WaitForChild("Event")
local Textbox = script.TextBox


Textbox.FocusLost:Connect(function()
    Remote:FireServer(Textbox.Text)
end)

The script to publishasync

local Event = script.Parent.Event
local MessagingService = game:GetService("MessagingService")

Event.OnServerEvent:Connect(function(player, text)

    MessagingService:PublishAsync("event", player.UserId, text)

end)

The messaging Service

local MessagingService = game:GetService("MessagingService")
local EventsFolder = game:GetService("ReplicatedStorage"):WaitForChild("RPFL")

local connection

function event(playerId, message)
    local eventName = message["Data"]
    local userName = playerId["Data"]
    --   EventsFolder.MessagingClients:FireAllClients(event)
    print(userName, eventName)
    task.wait(1)
    connection:Disconnect()
    task.wait(10)
    establishConnection()
end

function establishConnection()
    connection = MessagingService:SubscribeAsync("event", event)
end 

establishConnection()

This error started occuring with i added the playerId

3 Likes

have you tried printing Data?

message limit moment

1 Like
        • what exactly do i print about data
1 Like

i meant print message and playerID

I did that it just kept skipping to the error

so data does not exist, it probably doesnt replicate to the server

so it just doesnt have a way to get that players user?

sorry for being away for so long, but replication means the things on the client get to the server, in this case there may be no replication or in other words it doesn’t appear on the server

1 Like