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
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
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
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