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

How would I save a Humanoid stat for later use?

Asked by 7 years ago

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)
0
Use Data Stores . farrizbb 465 — 7y
0
Could you show me an example of how I could use that to store a players walk speed? SimpleFlame 255 — 7y
0
You would use a data store to save data when the player is not ingame, use a variable to store the def walk speed. User#5423 17 — 7y
0
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. SimpleFlame 255 — 7y

Answer this question