Error when trying to display table value on text

In the game im working on im trying to display a _G table value on some text, when I test I get the error “Attempt to index nil with userdata” here is my code:

   while wait() do

p = game.Players.LocalPlayer

script.Parent.Text = _G.ServerData[p].Shards

  end
2 Likes

You’re trying to locate a table key by a userdata value (the player). Try ServerData[p.Name] instead.

now it just says " [attempt to index nil with ‘RZZIO’"

Wait are you trying to access server data from the client with _G?

its a _G value so maybe thats the issue.

This should be done with events not while loops. You should use a event to update the text.

Correct. Here, try using a RemoteFunction.

You can use this to retrieve data from the server.

I tried that but it could not find the Remote inside PlayerGui, is there somewhere else I should put the remote.

I always default to Replicated Storage.

EDIT: You can sort it into folders if you’d like as well.

I do to I just didnt know if InvokeClient was diff

Ah no, it’s all the same. As long as both the client and server can find it, it should work.

thank you I will try that right now.

Can I use a remote that the server is already sending stuff through?

You can do it however you wish but I would strongly recommend using a RemoteFunction because the client may take time to load in and it can then call on the server when it’s ready to receive the data.

alright true, I will do this now.

I know with server when you InvokeServer when the server receives it you have to put player first in the (). Is there anything the same with the client, im asking because im getting the error [Argument 1 missing or nil] now

So for the client script, put:

RemoteFunction:InvokeServer()

for the server script, put:

RemoteFunction.OnClientInvoke = function(plr)
    return serverData;
end

sorry im just a bit confused,

server script:

        game.Players.PlayerAdded:Connect(function(p)

         game.ReplicatedStorage.ClientBoi:InvokeClient(_G.ServerData[p])

    end)

client:

    function game.ReplicatedStorage.ClientBoi.OnClientInvoke(v)

          script.Parent.Text = v.." Shards"

    end

Use a remote event since you’re not returning anything. InvokeClient requires a player to invoke that’s why it didn’t work. Also pls dont use _G and use module script instead

I would use module scripts but im worried because I know sense the client can change values in them that means exploiters can mess with values, if I didnt use _G exploiters could change there coins, pets, etc