Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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!

5 comments

1

Thank you for the help! It worked!

0

pls upvote if it helped http://prntscr.com/m1ymvo

0

Is it not showing up? Weird https://puu.sh/CqfpM/3deaf74d17.png

0

Congrats gioni you git your upvotes!

0

:))

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 comment

1

Then why would you post this as an answer?

This discussion is preserved as it was. New answers, comments, and votes are closed.