Leaderboards

From Goodblox Wiki
Revision as of 20:57, 23 June 2020 by Pizzaboxer (talk | contribs) (Created page with "{{CatUp|Tutorials}} __TOC__ == Introduction == This will show you how to make/edit the basic leaderboard. It may be necessary, if you are interested in KO's and Wipeouts, t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Introduction

This will show you how to make/edit the basic leaderboard. It may be necessary, if you are interested in KO's and Wipeouts, to access the most recent leaderboard, found in GAME OBJECTS. That leaderboard has a lot more scripting, but the additional script is dedicated to updating the KO's and Wipeouts. You can still edit it if you want.

The script

Eventually, you will find in any leaderboard script the following function "onPlayerEntered(newPlayer)" (or something similar). That is where the individual statistics for each player are made. function onPlayerEntered(newPlayer)

Below is where all the important CUSTOM bits are made. You can change almost all of it. The code is in the format local variableName = Instance.new("IntValue") variableName.Name = nameIWantToAppearOnScreen

The exception is the leaderstats variable.

	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

You CANNOT change the "leaderstats" unless you don't want the variables inside it displayed on the leaderboard. Note that the leaderstats variable itself doesn't show up.

So, if you wanted money, you'd do:

	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = "0"
	money.Parent = stats

To access the money of, say "Bob", you would use the command: game.Players.Bob.leaderstats.Money.Value = game.Players.Bob.leaderstats.Money.Value + 1 --increment Bob's money by 1.

You could continue to add more features, such as captures, points, mana, power, level, stage, minutes at place, etc. The rest of the script is below, but it is copied from the basic leaderboard.

	-- VERY UGLY HACK
	-- Will this leak threads?
	-- Is the problem even what I think it is (player arrived before character)?
	while true do
		if newPlayer.Character ~= nil then break end
		wait(5)
	end
	local humanoid = newPlayer.Character.Humanoid

Assigning of Events

If you want to, say, take away points every time the humanoid dies, you would need the following line: humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end ) Also, any other event of the humanoid can be put here, along with any other events related to the new player that aren't handled in any other script in your place. Just remember that the above line requires a special function "onHumanoidDied", which is not in this script.

-- start to listen for new humanoid

The same applies to the following line:

	newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
	stats.Parent = newPlayer --this part assigns the stats we made earlier to the player
end
game.Players.ChildAdded:connect(onPlayerEntered)

It is absolutely necessary for that part of the script to be present.

That should allow you to edit any leaderboard you like!

Complete leaderboard script

Here is an example of a complete leaderboard:

function onPlayerEntered(newPlayer)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

	local c = Instance.new("IntValue")
	c.Name = "Money"
	c.Value = 0

	c.Parent = stats

	stats.Parent = newPlayer 

	newPlayer.Changed:connect(function (property)
		if (property == "Character") then
			onPlayerRespawned(newPlayer)
		end
	end)
end

game.Players.ChildAdded:connect(onPlayerEntered)