Problem with a simple reputation system

A new game I’m working on has a system which lowers a player’s reputation if they kill an other player, but if a player with a very low reputation (which means they killed other players repeatedly) was killed by an other player, that player’s reputation will grow instead.

The issue is, the script I made for detecting if the killed player’s reputation is below a set number to decide if the player should receive or loose reputation did not work, it was a simple line of code using elseif, I tried to write it multiple times in different ways but it did not work.

Here’s the script which lowers the player’s reputation if they kill a player, that happens even if the reputation of the killed player is very low, is it possible to upgrade this script with a code which will decide if the reputation should be lowered or raised?

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 and creator.Value ~= nil then
				leaderstats.Reputation.Value = leaderstats.Reputation.Value - 100
			end
		end)
	end)
end)

I really appreciate all the help!

By the looks of it the leaderstats subtracting is not what’s wrong here, it’s the if statement, what I want you to do is, seperate the if statement into two and print at each line so we know where the error is coming from:

if creator ~= nil then
print(“Creator is not nil!”)
if creator.Value ~= nil then
print(“Creator’s value is not nil!”)
leaderstats.Reputation.Value = leaderstats.Reputation.Value - 100
end
end

Also I highly recommend using “leaderstats.Reputation.Value -= 100” it’s a new feature and is alot easier to use!

1 Like

After we know where the error is coming from we can focus on that instead!

the leaderstats you are setting are before it checks if the “creator” is nil, also was it intentional to get the leaderstats from the character, or are you trying to get them from the player?

if you’re trying to get them from the player it should look something like this:

local leaderstats = game.Players:FindFirstChild(creator.Name).leaderstats

I edited the script and it does perform exactly the same, should it look kinda like this?

lua 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)
It is supposed to only lower the player’s reputation if they kill someone else, I want to upgrade it so if the killed player’s reputation will be lower than a set value, the player’s reputation that killed them will grow instead.

I really have no idea, I do not know the difference between taking the leaderstats from the character or the player, the script performs as it should so it’s probably not a problem.

The “creator” is an objectvalue, its value is the player that killed someone. So there’s no point in doing game.Players:findfirstchild(creator.name).

You should do something like this

local creator = Humanoid:FindFirstChild("creator")
if creator then
--rest of ur code
end

This should work, no reason it shouldnt unless there’s something wrong with the weapon you are using. If it doesnt work, show the TagHumanoid function in your weapon.

oh, you can check whether their reputation is under a certain threshold by doing something if like

local Threshold = 1000

if leaderstats.Reputation.Value > Threshold then
--add reputation to whoever died

The script works correctly, as it takes the player’s reputation if they kill a player, I simply want to add a code which will instead raise their reputation, if the player they killed has a reputation level below a set number

ok,


--inside the player added event

if creator then
   if Reputation.Value >= whatevernumber then
        creator.Value.leaderstats.Reputation.Value+= whatever number
   end

end

im on phone so im too lazy to type it all out but is this what you’re trying to achieve?

It is what I am trying to achieve, I will place it inside the script and see if it works.

1 Like

While it isn’t my place to criticize, I just wanted to let you know a player could exploit this by getting an alt, farming it’s reputation down to under the threshold. And then just kill their main account to infinitely boost their main’s reputation.

It is true, but I will try to do something about it, maybe random spawnpoints which will be far away from each other + big safezones around them.

Where should I place this part of the script exactly? I think I placed it in the wrong line, where does the player added event start, also should I remove some lines as well?
Here’s the raw code

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 really don’t know where to put this line, tried everything and it’s not working