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)