Change player speed when they get a kill

Hello, I was wondering if anyone could help me. I am trying to create a script where whenever a player gets a kill, their walkspeed will increase by a set amount, maybe 2. Their walkspeed should not stay after they die.

I have been trying to figure it out but I am not much of a scripter so if anyone could help me that would be great.

Sure, but what do weapon or tool do they use to get a kill with?

They use a sword to get a kill.

Did you make the sword or is it a model?

A simple solution would be passing a function every time a player gets a kill. And then you grab the killer’s humanoid and add WalkSpeed to it.

I’m not sure how to have a function that recognizes when they get a kill. I’m pretty sure I can figure out the walkspeed part but could you perhaps help me further with the first part?

It’s a model right now, but I would maybe want to change it later. Would that make a difference?

Could you link the model? that would really help me understand what you need.

You could make it so that whenever any player dies in the game it checks for the last person who hit them. To do this you can add an ObjectValue inside of every player’s character that starts off as nil. Then whenever the player is hit you set that value to the attacker. When the player dies you check to see if the value contains a character.

You can implement something called, CreatorTags or simply to put it: A Kill Check

If you’re using a custom tool, I’d recommend looking at how those work :thinking: You could also use the ROBLOX’s default sword & check how they implement the CreatorTag that way

game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
	character:WaitForChild("Humanoid").Died:Connect(function()
		if character:FindFirstChild("CombatLog") ~= nil then
			local charKiller = character:FindFirstChild("CombatLog").Value -- Gives a character model
			local plrKiller = game.Players:GetPlayerFromCharacter(charKiller) -- Gives the player of the killer
			
			charKiller.Humanoid.WalkSpeed = charKiller.Humanoid.WalkSpeed + 1
			
		end
	end)
end)
end)

Here is a short script I drafted for checking that ObjectValue.

Where would I put this script? And would it be in a local one?

This script would be stored in ServerScriptService and would be a regular script.

This is because we called the PlayerAdded function so that we can catalog all players from the server’s end.
Also, if it was client-side it could be more prone to exploitation.

It’s not working for some reason, is there anything I could be doing wrong? I have it in ServerScriptService.

Chances are it’s probably what you’re truly looking for, can we see the tool script that handles the killing?

This is the model im using. 2019 LinkedSword - Roblox

You’ll have to of course do some of the coding yourself.

You’ll need a server-side script that creates an ObjectValue instance in every player’s character.

Once you do that, you need to make it so that every time a player is stabbed it checks for touching parts. If the part’s ancestor is a character then we know it’s the killer.

Then we just set the ObjectValue to the killer’s character.

Then when the player dies we check to see if the ObjectValue has a value. If it does, then the character inside the ObjectValue (the killer) gets a speed boost.

And to elaborate, it would be easiest to just create a new ObjectValue instance every time a character is added to the game.

game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local objValue = Instance.new("ObjectValue", character)
        objValue.Name = "CombatLog"
    end)
end)