Adding the players time to their killers time

I have a sort of sword fighting game and I want to make it where A kills B, A’s time is increased by how much time B has. I have tried to make this myself but I can’t.

	plr.CharacterAdded:connect(function(Character)
		local Humanoid = Character:FindFirstChild("Humanoid")
		if Humanoid then
			Humanoid.Died:connect(function()
				for i, Child in pairs(Humanoid:GetChildren()) do
					if Child:IsA('ObjectValue') and Child.Value and Child.Value:IsA('Player') then
						local Killer = Child.Value
						if Killer:FindFirstChild 'leaderstats' and Killer.leaderstats:FindFirstChild "Kills" then
							local Kill = Killer.leaderstats.Kills
							local Times = Killer.leaderstats.Time
							Times.Value = Times.Value + plr.leaderstats.Time.Value
							Kill.Value = Kill.Value + 1

						end
						return
					end
				end
			end)
		end
	end)
end)

The only problem is adding the time and nothing else. There isn’t any errors

1 Like

Can you post how you set up your explorer? (Also why the humanoid.Died function in a player.CharacterAdded function, they basically do the same thing except player.CharacterAdded fires when someone join the game and when their character dies. In your script you also put if Child:IsA(‘ObjectValue’) and Child.value:IsA(‘Player’). To me this doesn’t make sense so your checking if the child is an object value and then checking if it’s value is a player? Correct me if I’m wrong.

2 Likes

What do you mean by setting up explorer? I don’t know what that means but I will post my explorer.
image

3 Likes

I did Humanoid.Died because I didn’t want the script to fire when someone joins.

I did Child:IsA(‘ObjectValue’) because thats what someone told me to do. Im not a very advanced scripter so yea

1 Like

Sorry if i didn’t make my self clear what I meant was for you to show where the object value was and all it’s children.

2 Likes

Its not in the explorer, but people told me to use isa object value
image

2 Likes

Oh also when I said humanoid.died function in characterAdded function I was asking why are they are both there, shouldn’t it be one or the other?

2 Likes

The issue is that it doesn’t add the value +=1 to player B, right?

2 Likes

The issue is that it doesnt add the amount of time that player b had to player a
its like stealing time

1 Like

Ok so what I meant is show me where the object value is inside the humanoid and everything in it, you need to run the game then go into your humanoid.

2 Likes

image

2 Likes

Hmm where is the object value? Your code loops through everything in the humanoid and try’s to find the object value

2 Likes

Try replacing it with this, if it helps, that would be great.

local Humanoid = Character:WaitForChild("Humanoid")
2 Likes

Well, if the kill is added to the leaderstats, theres should be an objectvalue there right?

1 Like

No, it didnt help but i will keep thaat in my script

2 Likes

Creating an ObjectValue can be in the weapon or in other scripts. How do you use adding an ObjectValue?

2 Likes

i found an instance of object value in aa sword script

2 Likes

Ok let’s start from the beginning. We create two values one being a string to store the player who killed the other player (every death this resets) and the other value being the leader stat value. Then we get both the players leaderstat value and depending on who got the kill we add the dead player time to the one who got killed

2 Likes

After the hit, is the ObjectValue created in the humanoid?

1 Like

May I ask why is it an objectvalue and what object it is linked to?

1 Like