Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Sensing a player's walkspeed, and re-applying it after they die?

Asked by 6 years ago

In a game where you gain walkspeed throughout, how might you save the player's walkspeed when they die, then reapply it after they respawn, so it doesn't reset back to normal?

2 answers

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

In a server script:

local PlayerData = {}

game.Players.PlayerAdded:Connect(function(plr)
    PlayerData[plr.Name] = {
        WalkSpeed = 16 --set up table
    }
    --------------------
    plr.CharacterAdded:Connect(function(char)
        local humanoid = char:WaitForChild("Humanoid")
        humanoid.WalkSpeed = PlayerData[plr.Name].WalkSpeed --apply saved walkspeed
    end)
    --------------------
    local char = plr.Character or plr.CharacterAdded:Wait()
    local humanoid = char:WaitForChild("Humanoid")
    humanoid.Died:Connect(function()
        PlayerData[plr.Name].WalkSpeed = humanoid.WalkSpeed --record walkspeed
    end)
end)

Resources

CharacterAdded

PlayerAdded

Died

Accept and upvote if this helped!

1
Thank you for the help! It worked! SuperJumpman12 43 — 6y
0
pls upvote if it helped http://prntscr.com/m1ymvo Gey4Jesus69 2705 — 6y
0
Is it not showing up? Weird https://puu.sh/CqfpM/3deaf74d17.png SuperJumpman12 43 — 6y
0
Congrats gioni you git your upvotes! Ziffixture 6913 — 6y
0
:)) Gey4Jesus69 2705 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

In pseudo code it would look something like: player died --> save walkspeed in a variable player respawned --> set their walkspeed to the value of the variable we put in earlier.

I'm not gonna write you an entire script but you should use some of these for reference to construct around the pseudo code I described:

https://developer.roblox.com/api-reference/event/Humanoid/Died https://developer.roblox.com/api-reference/event/Player/CharacterAdded

1
Then why would you post this as an answer? Ziffixture 6913 — 6y

Answer this question