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

Player is not getting Rep for every kill?

Asked by 4 years ago

I want to make it to where the player gets Rep everytime they kill someone but it does not work.


local DataStore = game:GetService("DataStoreService") local SlayerStore = DataStore:GetDataStore("SlayerStore") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder",player) leaderstats.Name = "leaderstats" local Rep = Instance.new("IntValue", leaderstats) Rep.Name = "Reputation" Rep.Value = SlayerStore:GetAsync(player.UserId) or 100 print("Loaded!") end) game.Players.PlayerRemoving:Connect(function(player) SlayerStore:SetAsync(player.UserId, player.leaderstats.Rep.Value) print("Saved!") end) game.Players.LocalPlayer.ChracterAdded:Connect(function(character) character:WaitForChild("Humanoid").Died:Connect(function() local tag = character.Humanoid:FindFirstChild("creator") if tag ~= nil then local player = tag.Value local bounty = 20 local leaderstats = player:WaitForChild("leaderstats") leaderstats.Reputation.Value = leaderstats.Reputation.Value + bounty end end) end)

1 answer

Log in to vote
0
Answered by 4 years ago

You will reverse the character added and the player removing and don't use the LocalPlayer cause that's for only Local Script

Copy this code

local DataStore = game:GetService("DataStoreService") 
local SlayerStore = DataStore:GetDataStore("SlayerStore")


game.Players.PlayerAdded:Connect(function(player) 
    local leaderstats = Instance.new("Folder",player) 
    leaderstats.Name = "leaderstats" 

    local Rep = Instance.new("IntValue", leaderstats)
    Rep.Name = "Reputation"
    Rep.Value = SlayerStore:GetAsync(player.UserId) or 100

    print("Loaded!")

   player.ChracterAdded:Connect(function(character)-- Use the variable player. The script will know cause of the word CharacterAdded event so it means the player's character
        character:WaitForChild("Humanoid").Died:Connect(function()
            local tag = character.Humanoid:FindFirstChild("creator")
            if tag ~= nil then
                local player = tag.Value
                local bounty = 20

                local leaderstats = player:WaitForChild("leaderstats")
                leaderstats.Reputation.Value = leaderstats.Reputation.Value + bounty
            end
        end)
        end)
end)

game.Players.PlayerRemoving:Connect(function(player) 
    SlayerStore:SetAsync(player.UserId, player.leaderstats.Rep.Value)
    print("Saved!")
end)

Its not tested! I wish will worked!

Ad

Answer this question