How to get Other Player data?

The problem here is that you are using “target” as the first argument, which will be the client that invoked the RemoteFunction, add player, before the target argument

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

if they were making a data set, wouldnt it just reply with the client’s data? they say its returning nil

Also realized you just send the TextButton.Text, which would bring a string, so you would need to Invoke the remote like this

local TargetPlayer = game.Players:FindFirstChild(textButtons.Text)
local clickedplayerdata = getpdata:InvokeServer(TargetPlayer)

Yes, that is because they are sending a string, not a player through the remote, since the remote does .UserId, it would return nil since .UserId wouldn’t be valid of a string

1 Like

This should work perfectly fine,

Server:

ReplicatedStorage.GetOtherPlayerData.OnServerInvoke = function(player, 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 targetPlayer = game.Players:FindFirstChild(textbuttons.Text)
				local clickedplayerdata = getpdata:InvokeServer(targetPlayer)
				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

ohh wait i was away for a while let me try them yeah thanks to you guys for the help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.