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

How would I use my leaderboard to track kills?

Asked by 7 years ago
Edited 7 years ago

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
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. RedneckBane 100 — 7y

1 answer

Log in to vote
0
Answered by
DeepDev 101
7 years ago

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

0
Thanks, I get it now. I'm only a beginner scripter, but I get my mistake. InfernoExeuctioner 126 — 7y
0
No problem, I was like you but I gradually got better. Just keep on scripting and learning. DeepDev 101 — 7y
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. InfernoExeuctioner 126 — 7y
Ad

Answer this question