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

How Do I make a leaderboard that shows my kills and also allows me to buy things with the kills?

Hello! I'm having a very difficult time, In my game I made a gui to buy different swords, now I would like to make it to where, When I kill a player I get a point (On a leaderboard) And when I get up to a certain amount of kills/points, say 10 i can buy the golden katana, I havent been able to find or make a script compatible as I am very new.... Here's the Script for the button in the gui ****~~~~~~~~~~~~~~~~~




repeat wait() Player = game.Players.LocalPlayer Button = script.Parent Item = game.ReplicatedStorage:FindFirstChild("Golden Katana") Cost = 50 Money = Player.leaderstats.Money until

Button.MouseButton1Down:connect(function(purchase) if Money.Value > (Cost - 1)then Money.Value = Money.Value - Cost local a = Item:Clone() a.Parent = Player.Backpack local b = Item:Clone() b.Parent = Player.StarterGear end end)




**
**
If you need the actual Gui Script, I will post it as well, please help!

2 answers

Well, you've got everything set up correctly within this script, so all that's left is to do the things needed in other scripts.

Assuming you want kills to increase the Money value of the player, you'll need to do this:

First we need to open up the scripts within the weapons in the shop, or really just all weapons potentially available. Find the lines in the scripts that tell the weapon to deal damage -- then in the function that tells it do that, you'll need to add an if statement after the line that deals damage that asks the script whether the humanoid it just hit is dead, AKA whether it's health is 0.

By using that, we can determine that the sword just killed someone, and so using Parent chains you can make the player holding the weapon's Money value to increase. The final code should be something like this:

(dealing damage)
if hit.Humanoid.Health == 0 then
	script.Parent.Parent.Parent.leaderstats.Money.Value = script.Parent.Parent.Parent.leaderstats.Money.Value + (number)
end

-- Ascending up the ancestry, the Parent chain shown above would be the Script, Weapon, Backpack, Player,  respectively.

By the way, you don't have to reduce the cost by 1 -- you can just use the Greater Than or Equal To sign which is >=.

1 comment

0

Thank you!

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