Greetings Everyone,
I need some help with this code I have. I want it that if player1 kills player2 then player1 will get some leaderstats, In my case 1 Kill and 25 Coins. So I want to integrate this into my main game script where it already has a function that runs whenever someone kills another person or when a person dies. So this script is not completely coded by me I have just made countless modifications to it but I cant seem to make the modification I talked about above. If anyone can help me it will be Extremely Appreciated! If you have any questions about what I exactly want, just ask! PLEASE VIEW LINES 37 - 43 THAT IS WHERE I NEED HELP! Here is the code:
local dataStores = game:GetService("DataStoreService"):GetDataStore("WinsDataStore")
local dataStores = game:GetService("DataStoreService"):GetDataStore("CoinsDataStore")
local defaultWins = 0
local playersLeft = 0
game.Players.PlayerAdded:Connect(function(player)
playersLeft = playersLeft + 1
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Value = 0
wins.Parent = leaderstats
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats
local playerData = Instance.new("Folder")
playerData.Name = player.Name
playerData.Parent = game.ServerStorage.PlayerData
local equipped = Instance.new("StringValue")
equipped.Name = "Equipped"
equipped.Parent = playerData
local inventory = Instance.new("Folder")
inventory.Name = "Inventory"
inventory.Parent = playerData
player.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
if character.Humanoid and character.Humanoid:FindFirstChild("creator") then
game.ReplicatedStorage.Status.Value = tostring(character.Humanoid.creator.Value).. " Killed "..player.Name
end
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
player:LoadCharacter()
end)
end)
-- Data Stores
local player_data
local weaponsData
local equippedData
local coins_data
pcall(function()
player_data = dataStores:GetAsync(player.UserId.."-Wins")
end)
pcall(function()
coins_data = dataStores:GetAsync(player.UserId.."-Coins")
end)
pcall(function()
weaponsData = dataStores:GetAsync(player.UserId.."-Weps")
end)
pcall(function()
equippedData = dataStores:GetAsync(player.UserId.."-EquippedValue")
end)
if player_data ~= nil then
-- Player has saved data , load it in
wins.Value = player_data
coins.Value = coins_data
else
-- New player
wins.Value = defaultWins
coins.Value = defaultWins
end
if weaponsData then
for _, weapon in pairs(weaponsData) do
if game.ServerStorage.Items:FindFirstChild(weapon) then
local weaponClone = game.ServerStorage.Items[weapon]:Clone()
weaponClone.Parent = inventory
print(weapon.." loaded in!")
end
end
if equippedData then equipped.Value = equippedData
player:WaitForChild("PlayerGui")
game.ReplicatedStorage.SendEquipped:FireClient(player,equippedData)
end
else
print("No weapons data")
end
end)
local bindableEvents = Instance.new("BindableEvent")
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
dataStores:SetAsync(player.UserId.."-Wins",player.leaderstats.Wins.Value)
end)
pcall(function()
local weapons = game.ServerStorage.PlayerData[player.Name].Inventory:GetChildren()
local weaponsTable = {}
for _, v in pairs(weapons) do
table.insert(weaponsTable,v.Name)
end
dataStores:SetAsync(player.UserId.."-Weps",weaponsTable)
if game.ServerStorage.PlayerData[player.Name].Equipped.Value ~= nil then
local equippedVal = game.ServerStorage.PlayerData[player.Name].Equipped
dataStores:SetAsync(player.UserId.."-EquippedValue",equippedVal.Value)
end
end)
playersLeft = playersLeft - 1
bindableEvents:Fire()
end)
game:BindToClose(function()
-- This will be triggered upon shutdown
while playersLeft > 0 do
bindableEvents.Event:Wait()
end
end)
Thankyou for any help, epicnmac

2 comments
Please view lines 37 - 43 that is where I need help!
If anyone knows the answer please write it down!????