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)
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!
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.
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.
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
--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?
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.
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)