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

How would you add points to another players leaderstats?

Asked by 10 years ago

Hello, today I am attempting to build a WIJ like in-game point system. I have already made an admin list, that only allows the admins to see a control board.

The problem I am having is taking the information from a textbox (which would be a players name), and then getting that players current stats. I would also like to know how you would add points to that player. Here is how the GUI is laid out; http://gyazo.com/7a4e68d9fbc009b157fbcd6fa6b0650b

Help would be greatly appreciated.

2 answers

Log in to vote
1
Answered by 10 years ago

Firstly you would need to have a something to trigger the function to happen (Button) and something to set the value of what you want to change it to, then you would need to run this in the function:

stat = "" -- Enter stat name here
amount = script.Parent.Amount.Value -- This value would have to be updated somehow (USE AN IntValue)

p = game.Players:FindFirstChild(script.Parent.TextBox.Text)
if p ~= nil then
    stats = p:FindFirstChild("leaderstats") -- Assuming it is a leaderboard stat
    if stats ~= nil then
        stats:FindFirstChild(stat).Value = amount
    end
end

The script should be in the frame (Same location as the TextBox), you will need an IntValue in that place as well, but make sure it updates before it does all of this stuff.

Ad
Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

As above stated, you need an event or trigger to be fired to make this happen. I'll make mine for a possible TextButton that you would use to click after one typed in the desired name in the TextBox.

-- * means that the value of the variable may be changed

stat = "Points" -- *
amount = 20 -- *
TB = script.Parent.TextBox

script.Parent.MouseButton1Down:connect(function() -- * event may be changed to MouseButton1Click
    if not TB.Text == "" then
        p = game.Players:findFirstChild(TB.Text)
        if p then
            stats = p:findFirstChild("leaderstats")
            if stats then
                points = stats:findFirstChild(stat)
                if points then
                    points.Value = points.Value + amount
                end
            end
        end
    end
end)

Answer this question