Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would you add points to another players leaderstats?

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

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.

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.