Hi! I am currently trying to make a script which changes the character’s humanoid properties (like walkspeed or jumppower) reliably. My goal is to make these changes stackable upon each other, for example 2 walkspeed penalty intvalues stack with each other and subtract the stacked value off of the character’s humanoid walkspeed until one of the intvalues have been removed from the character’s folder.
The code below is how I’ve done it, but it doesn’t work very well. For instance, if the stacked penalties equal to a bigger value than the walkspeed value, the walkspeed value doesn’t go into the negatives. The script will however give back the walkspeed it tried to take away, which will lead to the walkspeed being bigger than it should be.
local Character = script.Parent
local Humanoid = Character.Humanoid
local ActionFolder = Character:WaitForChild("Actions")
local Temp = nil
ActionFolder.ChildAdded:Connect(function(Item)
wait()
if Item.Name == "WSPenalty" then
Humanoid.WalkSpeed = Humanoid.WalkSpeed - Item.Value
Temp = Item.Value
elseif Item.Name == "WSBoost" then
Humanoid.WalkSpeed = Humanoid.WalkSpeed + Item.Value
Temp = Item.Value
elseif Item.Name == "NoRotate" then
Humanoid.AutoRotate = false
end
end)
ActionFolder.ChildRemoved:Connect(function(Item)
wait()
if Item.Name == "WSPenalty" then
Humanoid.WalkSpeed = Humanoid.WalkSpeed + Temp
elseif Item.Name == "WSBoost" then
Humanoid.WalkSpeed = Humanoid.WalkSpeed - Temp
elseif Item.Name == "NoRotate" then
Humanoid.AutoRotate = true
end
end)
Thank you for reading my post!