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

Player is not getting Rep for every kill?

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

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!

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