Hey Robloxians,
I have made a npc which gives kill points everytime it is eliminated, how do I make that if a player gets 2 or more kills, that player’s speed will increase for 5 seconds and then it will be back to normal and the player kills reset?
My kill value is inside player in the folder called leaderstats and the value name is ZombieTempKills
That’s pretty easy to make, you can make a number value that will store how much kills player has, and then set it to 0 and increase speed once it reaches the amount of 2:
local AmountOfKills -- your number value
local Character -- define character here
local Increase = 5 -- define increase here
local defaultSpeed = 16 -- the default speed
AmountOfKills.Changed:Connect(function(amount)
if amount == 2 then
AmountOfKills.Value = 0
Character.Humanoid.WalkSpeed += increase
task.wait(5)
Character.Humanoid.WalkSpeed = defaultSpeed
end
end)
local WALK_SPEED_INCREASE = 5
local INCREASE_TIME = 5
local Humanoid = Character:WaitForChild("Humanoid")
local KillsValue = Character:WaitForChild("Kills") -- change the path if it's different
local function OnChanged(Value: number)
if Value < 2 then return end
KillsValue.Value = 0
Humanoid.WalkSpeed += WALK_SPEED_INCREASE
task.wait(INCREASE_TIME)
Humanoid.WalkSpeed -= WALK_SPEED_INCREASE
end
KillsValue.Changed:Connect(OnChanged)
I suggest you to learn basics first before actually trying to make something on your own. The script could be placed anywhere where it will run, but preferably on the server side, so it won’t be exploitable.
local WALK_SPEED_INCREASE = 5
local INCREASE_TIME = 5
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local KillsValue = player:WaitForChild("leaderstats").ZombieTempKills
local function OnChanged(Value: number)
if Value < 2 then return end
KillsValue.Value = 0
Humanoid.WalkSpeed += WALK_SPEED_INCREASE
task.wait(INCREASE_TIME)
Humanoid.WalkSpeed -= WALK_SPEED_INCREASE
end
KillsValue.Changed:Connect(OnChanged)
local Character = game.Players.LocalPlayer -- define character here
local AmountOfKills = Character.leaderstats.ZombieTempKills -- your number value
local Increase = 20 -- define increase here
local defaultSpeed = 16 -- the default speed
AmountOfKills.Changed:Connect(function(amount)
if amount == 2 then
AmountOfKills.Value = 0
Character.Humanoid.WalkSpeed += Increase
task.wait(5)
Character.Humanoid.WalkSpeed = defaultSpeed
end
end)
local Character = game.Players.LocalPlayer -- define character here
local AmountOfKills = Character.leaderstats.ZombieTempKills -- your number value
local Increase = 20 -- define increase here
local defaultSpeed = 16 -- the default speed
AmountOfKills.Changed:Connect(function(amount)
if amount == 2 then
AmountOfKills.Value = 0
Character.Character.Humanoid.WalkSpeed += Increase
task.wait(5)
Character.Humanoid.WalkSpeed = defaultSpeed
end
end)
Is your script a local script? The script must be a local script and parented to a StarterPlayerScripts. Also the problem might be that leaderstats folder didn’t appear before the script ran, so try adding WaitForChilds.
u are trying to get with amount any value of the leaderstats try use that:
local player = game.Players.LocalPlayer -- define player here
local Character = player.Character or player.CharacterAdded:Wait() -- define character here
local AmountOfKills = player:WaitForChild("leaderstats").ZombieTempKills -- your number value
local Increase = 20 -- define increase here
local defaultSpeed = 16 -- the default speed
AmountOfKills.Changed:Connect(function(amount)
if amount >= 2 then
AmountOfKills.Value = 0
Character:WaitForChild("Humanoid").WalkSpeed += Increase
task.wait(5)
Character:WaitForChild("Humanoid").WalkSpeed = defaultSpeed
end
end)