So by default, a player's walk speed is set to 16 which is fine. But in my game, I have attacks that can remove speed or add it. What I want to do is make a variable for the current walk speed a player has and save it so I can bring it back later. For example: When a player gets hit by an attack I want them to get slowed by 50%. Now depending on the walk speed they currently have 50% can mean anything. So I want to save the walk speed they had when they got hit be it 16 or 32 then divide it by 2 (because 50%) and then set their walk speed back to the original value they had. TL;DR: Want to save a player's current speed, edit it, then change it back to the original. Here's what I tried:
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
local curWalkSpeed = h.WalkSpeed
local WalkSpeed = curWalkSpeed
if h~=nil then
WalkSpeed = WalkSpeed / 2
wait(1)
WalkSpeed = curWalkSpeed
end
end
script.Parent.Touched:connect(onTouched)

5 comments
Use Data Stores .
Could you show me an example of how I could use that to store a players walk speed?
http://wiki.roblox.com/index.php?title=Saving_Player_Data
You would use a data store to save data when the player is not ingame, use a variable to store the def walk speed.
Yeah thats what I thought. Data stores isn't what Im looking for in this case. Kingdom5 can you show me an example because I've tried to make a variable for the walk speed and that won't work.