Here in the script, when I click on a player the TextLabel and Image becomes a value of the leaderstats, but the problem is that the local hum = target.Parent
is looking for the player in the game.workspace
, how do I get the local hum = target.Parent
to go to game.Players
?
Is that leaderstats are in game.Players
and not game.workspace
local player = game:GetService("Players").LocalPlayer local mouse = player:GetMouse() local sc = script.Parent.Holder local selection = Instance.new("SelectionBox") selection.Color3 = Color3.fromRGB(255, 0, 0) selection.Parent = script mouse.Button2Down:connect(function() local target = mouse.Target if not target then selection.Adornee = nil else local hum = target if hum ~= nil then sc.Player.Image = "https://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&userId="..hum.UserId --PlayerID sc.Attack.Text = "Attack: "..hum.leaderstats.Attack.Value --leaderstats sc.Agility.Text = "Agility: "..hum.leaderstats.Aggility.Value --leaderstats sc.Defense.Text = "Defense: "..hum.leaderstats.Defense.Value --leaderstats sc.Ki.Text = "Ki: "..hum.leaderstats.Energy.Value --leaderstats sc.Username.Text = ""..hum.Name --PlayerName end end end)
Error line 16 userid is not a valid member of part
BasePart
. You'll have to get the player manually, using GetPlayerFromCharacter
, a method of Players
. The character is a Model
.local Players = game:GetService("Players") local player = Players.LocalPlayer local mouse = Player:GetMouse() local UserInputService = game:GetService("UserInputService") UserInputService.InputBegan:Connect(function(inp) if inp.UserInputType == Enum.UserInputType.MouseButton2 then local target = mouse.Target if target then local targetPlayer = Players:GetPlayerFromCharacter(target.Parent) if targetPlayer and targetPlayer ~= player then sc.Player.Image = "https://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&userId="..targetPlayer.UserId --PlayerID sc.Attack.Text = "Attack: "..targetPlayer.leaderstats.Attack.Value --leaderstats sc.Agility.Text = "Agility: "..targetPlayer.leaderstats.Aggility.Value --leaderstats sc.Defense.Text = "Defense: "..targetPlayer.leaderstats.Defense.Value --leaderstats sc.Ki.Text = "Ki: "..targetPlayer.leaderstats.Energy.Value --leaderstats sc.Username.Text = ""..targetPlayer.Name --PlayerName end end end end)
Connect
, as connect
is deprecated and should not be used in new work. Read more on deprecation here.It's the same as how you accessed the LocalPlayer.
local tag = "xPolarium" if game.Players[tag] then print("Found our desired player.") end
In your case, you would use the name of hum to locate the player in Players.
Also use Connect
over lower case connect
as the latter is depricated and is likely to be removed in the future. Good practice to code right than risk anything.