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