Help with a simple reputation system

A game I’m currently working on has a system which lowers the player’s reputation if they killed an other player, I wanted to upgrade it, so when the player who was killed has a reputation below zero (which means they killed players repeatedly), the person who killed that player receives reputation instead of loosing it.

Here’s the already working code which ONLY lowers the reputation by killing players.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.Died:Connect(function(died)
			local creator = Character.Humanoid:FindFirstChild("creator")
			local leaderstats = creator.Value:FindFirstChild("leaderstats")
			if creator ~= nil then
				print("Creator is not nil")
				if creator.Value ~= nil then
					print("creator's value is not nil")
					leaderstats.Reputation.Value -= 100
				end
			end
		end)
	end)
end)

I tried to add a script which would detect if the killed player has a bad reputation, which would result in increasing the reputation of the player who killed them, instead of lowering it. I failed to do that multiple times.

I’m thankful for all the help!

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.Died:Connect(function(died)
			local creator = Character.Humanoid:FindFirstChild("creator")
			local leaderstats = creator.Value:FindFirstChild("leaderstats")
			if creator ~= nil then
				print("Creator is not nil")
				if creator.Value ~= nil then
					-- Is your reputation good or bad?
					if 0 <= player.leaderstats.Reputation.Value then
						leaderstats.Reputation.Value -= 100
					else
						leaderstats.Reputation.Value += 100
					end
				end
			end
		end)
	end)
end)

That should do it for you.

1 Like

It’s working, thank you so much!