Okay, the point is that when a player dies his speed, for some reason constantly fluctuates. That is, it first, has the value that was before death, and a second later has a new value that has humanoid.walkspeed. And in a second it is the old one again. And so on, and humanoid.WalkSpeed, is not saved. And according to the script it should. That is, it should work that when a player dies his speed is saved. What to do?
It appears that you never set the playerβs WalkSpeed to the value of the NumberValue βSpeedβ upon their characterβs respawn.
Wait, what do you mean? If I write humanoid.WalkSpeed = humanoid.WalkSpeed, it still wonβt save, but if I write humanoid.WalkSpeed = speed.Value, it will be as it was.)
You are not setting the Humanoid Walkspeed when the character respawns, you only set it when it dies. Also you should remove the while loop as it is not necessary for this.
To set the Humanoid Walkspeed upon respawn, just set the Walkspeed to the Number Value under the CharacterAdded event.
plr.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
if speed then
humanoid.WalkSpeed = speed.Value -- sets 'WalkSpeed' to the 'speed' value
end
-- the rest of the code
end)
Okay, about death fixed, but I still have the value jumps in leader stats, that is, when you die it shows so β¦ 30β¦32β¦31β¦33β¦32, and so on. That is, as I understand it does not keep up with the numbers or something like that. Because if the player will continue to die, it will increase and will be like 30β¦33β¦31β¦35β¦32, and so on. I didnβt remove the while wait(1) do loop. Because when I removed it then the value in leader stats simply did not change. But removing Humanoid.died helped) But still, what to do with this delay? As I understand it is necessary somewhere to put wait but where?
I believe you should also remove the addSpeed function, as that is increasing the humanoid WalkSpeed every second, which is also increasing the value.
So I kind of need to increase the playerβs speed every second, thatβs the idea.
Iβm not quite understanding the problem then. Do you want the βspeedβ value to change every second, or the opposite? Could you please explain so I can understand your issue?
Okay, I need the value to change every second. And it works, but for some reason with a slight delay, that is. I have two parameters. 1. humanoid.walkspeed is what I change. 2. speed is my variable that stores humanoid.walkseed I use it to output to leaderstats the playerβs speed value. But for some reason when a player dies his walkspeed is saved but speed starts fluctuating, i.e. it starts outputting data like this. First, the base number was. For example 30. And then it writes like this every second: 30β¦32β¦31β¦33β¦32 that is, itβs in too much of a hurry and goes forward. And if it keeps dying, it will only get worse and will rush forward a few values. As I understand it, I need to set somewhere to wait so that when a player dies the speed will not rush and will not show the value ahead.
I hope Iβve made myself clear.)
Alright, so if you use a variable that acts as a changing constant, with a default, instead of one that will reset, like how walkspeed resets to its own constant of 16, we make one that doesnβt reset.
local PreviousSpeed = 16 --- 16 is default on all roblox humanoids
function addSpeed(hum)
spawn(function()
while task.wait(1) do
PreviousSpeed += 1
hum.WalkSpeed = PreviousSpeed
speed.Value = hum.WalkSpeed
end)
end
Okay, where exactly does this have to be put in?
Just replace your add speed function with it.
And once you replace it with your add speed function, also remove the hum.Died function or it will reset or vary.
OOPS my bad, I forgot a end in the function it should look like this:
local PreviousSpeed = 16 --- 16 is default on all roblox humanoids
function addSpeed(hum)
spawn(function()
while task.wait(1) do
PreviousSpeed += 1
hum.WalkSpeed = PreviousSpeed
speed.Value = hum.WalkSpeed
end
end)
end
This should also replace your other while wait(1.1), as it does all 3, it updates the hum, updates speed, and it updates the leaderstats.
Put the add speed function inside the PlayerAdded function.
Okay, I did it, I ran it. And now, for example, when I just started the player is given 1 per second, but for some reason when I die, he begins to be given 2 per second, etc. That is, by the fifth time, I see that he has +5 in a second. It should not be, it should just be +1 per second.
Sorry for contradicting what I just said but move the function outside the player-added function, where it was before. I edited the function a bit.
local PreviousSpeed = 16 --- 16 is default on all roblox humanoids
function addSpeed(hum,Player)
spawn(function()
while task.wait(1) do
PreviousSpeed += 1
hum.WalkSpeed = PreviousSpeed
Player.speed.Value = hum.WalkSpeed
end
end)
end
And when you do addSpeed make sure you do addSpeed(hum,Player)
Also since youβre firing it in character added it will duplicate when the character resets.
So instead of using a character-added function, youβll have to define humanoid directly.
So
local char = plr.Character
if char and char:IsA("Model") then
local hum = char:WaitForChild("Humanoid")
addSpeed(hum,plr)
end