Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I get the player leaderstats with this script?

Asked by 5 years ago
Edited 5 years ago

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

0
try mouse.Button2Down:connect(function(target) target = mouse.Target KenUSM 53 — 5y
0
Also it should just be hum = target not target.Parent, target.Parent will give you the humaniod, target gives you the Player in Players KenUSM 53 — 5y
0
if sc is the leaderstats then it should be sc.Parent = target and sc.Name needs to = "leaderstats" if your trying to use the game's default leaderstats. KenUSM 53 — 5y
0
@KenUSM Button2Down does not pass anything, don't give OP false information. User#19524 175 — 5y
0
I've done everything I say but the error on line 15 -- userid is not a valid member of part ToddyWars 41 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

What you're doing, is trying to get the player from a 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)

On a side note, switch to Connect, as connect is deprecated and should not be used in new work. Read more on deprecation here.

Ad
Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
^ User#19524 175 — 5y
0
I'll try. ToddyWars 41 — 5y
0
I tried this way: mouse.Button2Down: connect (function () local target = mouse.Target if game.Players [target] then --and did not work ToddyWars 41 — 5y

Answer this question