how would you go about changing a stat thats being influenced by multiple inputs, for example movement speed. like a movement ability and run ability adding speed but uh oh you stopped sprinting and then the ability ended and now your speed is slower than the default! how would you avoid stuff like this? (and just rigidly setting it to 0 wouldnt work because like i said it would over lap the other inputs)
You should look into Boost or something similar. (It’s currently deprecated? Not too sure why, but you can just make your own that does the same thing.)
gave me a vague idea but still if someone does have any sort of help it would be great
Here, use my MinLock module!
local MinLock = {}
MinLock.__index = MinLock
function MinLock.new(_defaultValue)
local self = setmetatable({}, MinLock)
self.Keys = {}
self.DefaultValue = _defaultValue
return self
end
function MinLock:Set(name, value)
if not value then
self.Keys[name] = nil
else
self.Keys[name] = value
end
local minValue
for name, value in self.Keys do
if not minValue or value < minValue then
minValue = value
end
end
minValue = minValue or self.DefaultValue
self.Value = minValue
return minValue
end
return MinLock
Basically create a new lock:
--Default walkspeed set to 16.
local walkspeed = MinLock.new(16)
Set the walkspeed like so:
Humanoid.WalkSpeed = walkspeed:Set("Running", 25)
If you have both running = 25, and crouching = 12, then walkspeed will be set to 12.
To remove a lock use
Humanoid.WalkSpeed = walkspeed:Set("Running")
Module will keep track of all values and return the lowest. If there are no locks set, it will return default value.