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

How would I use my leaderboard to track kills?

I already have a simple script done that would track down kills and give weapons. The problem is that I don't know how to specific if a player has an amount of kills. I want the player to have 1 kill before getting the GLOCK 17. And yes, I already have my leaderboard setup.

local player = game:GetService("Players").LocalPlayer
player.leaderstats.Kills.Value = 1 --what to do with this line?
game.ServerStorage.Guns["GLOCK 17"]:Clone().Parent = player.Backpack
print("script success")

EDIT: I made a new script based off of CodeOverload's suggestions but I don't know why it's not working. Note that the game I am making runs like this: Someone kills a person, they gain a better weapon. I grabbed a quick death and kills script free model that works.

local player = game:GetService("Players").LocalPlayer
	if player.leaderstats.Kills.Value == 1 then --tracks the player's kills
		game.ServerStorage.Guns["USP-S"]:Clone().Parent = player.Backpack --gives gun
		print("usp-s") --just to make sure you get the gun
		if player.leaderstats.Kills.Value == 2 then --tracks player's kills
			player.Backpack["USP-S"]:Destroy() --destroys previous gun
			game.ServerStorage.Guns["Beretta"]:Clone().Parent = player.Backpack --gives gun
			print("beretta") --just to make sure you get the gun
		end
	end

1 comment

0

On line 2, you're setting the value of "Kills" to 1 instead of checking if it's 1. Use an conditional statement to check or better yet, connect a function to the Changed() event and then put a conditional in there.

1 answer

✓ Accepted answer

I think you forgot the function, with only:

local player = game:GetService("Players").LocalPlayer
    if player.leaderstats.Kills.Value == 1 then 
        game.ServerStorage.Guns["USP-S"]:Clone().Parent = player.Backpack
        print("usp-s")
        if player.leaderstats.Kills.Value == 2 then
            player.Backpack["USP-S"]:Destroy()
            game.ServerStorage.Guns["Beretta"]:Clone().Parent = player.Backpack
            print("beretta")
        end
    end

it only runs one time. If I was you I'd use this script, it will not be flawless but this will do:

function changeweapon ()
local player = script.Parent.Parent
local kills= player.leaderstats.Kills
    if kills.Value == 1 then 
        game.ServerStorage.Guns["USP-S"]:Clone().Parent = player.Backpack
        print("usp-s")
end
    if kills.Value == 2 then
        player.Backpack["USP-S"]:Destroy()
        game.ServerStorage.Guns["Beretta"]:Clone().Parent = player.Backpack
        print("beretta")
        end
    end
script.Parent.Parent.leaderstats.Kills.Changed:connect(changeweapon)
wait(.2)
changeweapon()

Place the script above in a local script and put the local script in game.StarterPlayer.StarterPlayerScripts

3 comments

0

Thanks, I get it now. I'm only a beginner scripter, but I get my mistake.

0

No problem, I was like you but I gradually got better. Just keep on scripting and learning.

0

I used this script and edited it a little. The problem was that it kept saying that the weapons were not valid when I killed someone. It only works if I insert the kills value through explorer.

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