How to get Other Player data?

Im currently making a script when if you click a text button it will show the player data like the equipped object they are using, and its a table data btw. However i dont understand how would i pass that player data to the client because its not the player itself but other player

Server:

ReplicatedStorage.GetOtherPlayerData.OnServerInvoke = function(target)
	return data[target.UserId]
end

Client

for i,textbuttons in pairs(servermenu:GetChildren()) do
	if textbuttons:IsA("TextButton") and textbuttons.Name ~= "LeaveServer" then
		textbuttons.Activated:Connect(function()
			if textbuttons.Text ~= "" then
				local clickedplayerdata = getpdata:InvokeServer(textbuttons.Text)
				if clickedplayerdata then
					playergui.MainGui.PlayerStatsInformation.Visible = true
					playergui.MainGui.PlayerStatsInformation.Playername.Text = textbuttons.Text
					playergui.MainGui.PlayerStatsInformation.Playerlvl.Text = "Lv. " .. clickedplayerdata.Level
					for i,unitsselected in pairs(clickedplayerdata.SelectedTowers) do
						local unitsmodel = game.ReplicatedStorage.Units:FindFirstChild(unitsselected):Clone()
						local unitstats = require(unitsmodel:WaitForChild("Stats"))
						local oldbutton = playergui.MainGui.PlayerStatsInformation.EquippedUnit:FindFirstChild(unitsselected)

						if oldbutton then
							oldbutton:Destroy()
						end

						local buttongui = playergui.MainGui.PlayerStatsInformation.EquippedUnit.Layout:Clone()

						buttongui.Name = unitsselected
						unitsmodel.Parent = buttongui.ViewportFrame.WorldModel
						buttongui.Visible = true
						buttongui.Parent = playergui.MainGui.PlayerStatsInformation.EquippedUnit
						
			
						
					end
				end
			end
			
		end)
	end
end
1 Like

Send it as a parameter on the invoke then on invokes or remotes the parameters will always be
(player,params)

Like this? im typing this manually so it can be wrong

ReplicatedStorage.GetOtherPlayerData.OnServerInvoke:Connect(function(target)
	return data[target.UserId]
end

The client that invoked the server is always the first parameter

so basically do a second parameters like u mentioned?

Just move the target parameter along by one and name the first one player or something like that

ReplicatedStorage.GetOtherPlayerData.OnServerInvoke = function(player,target)
	return data[target.UserId]
end

I did this but now it wont return anything

Have you tried printing out the data or the parameters to see if it is fired?

for the client i tried printing the textbutton text for the user name it does print but for the Server or the onserverinvoke it does print my name. and yeah it return “nil”

Well your passing through text so there will be no User ID value of it. To fix do

game.Players:GetUserIdFromNameAsync(target) -- might be a bit different spelling / syntax as on mobile

-- this gets the user ID of the player based on their name so just replace target.UserId with that

I play tested it with Roblox built in testing and it returns nil because they are Player1 and Player2 do i have to test it with real user?

i thought it was

ReplicatedStorage:WaitForChild("GetOtherPlayerData"):Connect(function(player, target)
    return data[target.UserId]
end)

tried them but they returns nil

hey @SHARPTHRIX can I see the script context?

So when a user click a textbutton with a player name in it, It will show what item they are equipping and their level. The data is stored inside a table data btw

let me go see how remote functions work rq

RemoteFunctions dont use :Connect, you just use = function, and the first param will always be the player who invoked, the params after the first will be what the client sent

RemoteFunction.OnServerInvoke = function(RemoteCaller: Player, RequestedTarget: number) --> Client (RemoteCaller) sends the UserId of the players data they want
    return data[RequestedTarget]
end

oh

wow i feel dumb mb

this stupid char limit

yeah i used = function for my old code

revert to your old version, and i would check your table to make sure that the key actually exists

can i see script context?