Im trying to make a game where when you kill someone your speed goes up and when you die you get slower.
local player = game:GetService("Players").LocalPlayer -- Assuming you're working with local player
local speed = 16 -- Default speed value
local deathSpeedDecrease = 4 -- Amount to decrease speed when the player dies
local killSpeedIncrease = 2 -- Amount to increase speed when the player gets a kill
local function handleDeath()
speed = speed - deathSpeedDecrease
local function handleKill()
speed = speed + killSpeedIncrease
local function updateSpeed()
player.Character.Humanoid.WalkSpeed = speed -- Adjust the player's speed
-- Listen for player deaths and kills
-- Assuming you have a way to track player kills, listen for kills and call the kill function
-- Continuously update the player's speed
while wait(0.1) do
Whats wrong? The speed doesnt change when you kill/die. The weapon is a gun. I tested it.
Post is wrongly written. Tell us what exactly doesn’t work. The increase, the decrease or both? Is the code server script or client script? Have you checked the console?
Debug your code by placing breakpoint or prints.
It’s waste of your and our time to investigate what’s wrong in your code if you didn’t test it properly.
–an event for when the bullet hits something , for example if you use Raycast to determine where the bullet goes, you can just check raycast_result.Instance
–inside raycast_result.Instance, insert a value called “target”.
raycast_result.Instance should be the player that the bullet hits.
now, you can check target.Parent.Humanoid’s health, and if it’s lower than 1, you killed them, if that happens then you fire to a ServerScript and you change the player’s speed from there.
it’s never the best idea to have a “character_added:connect” event and put a “humanoid.died” event inside of it. remember that character_added fires whenever any character is added, and just adding another listener inside of it just wastes time when there’s easier and more optimized ways of doing this.