Speed Boost

Speed Boost


Where to put this script


Put this script inside the part that will activate the speed boost when touched

Speed Boost


local speedPart = script.Parent
-- Set a variable for boosted speed power
local SPEEED_POWER = 200
local function speed(otherPart)
    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
        local currentSpeed = humanoid.WalkSpeed
        if currentSpeed < SPEEED_POWER then
            humanoid.WalkSpeed = SPEEED_POWER
            wait(10)
            humanoid.WalkSpeed = currentSpeed
         end
    end
end
speedPart.Touched:Connect(speed)


Line by Line


local speedPart = script.Parent    ---Links the script to the part for easy reference


local SPEEED_POWER = 200    -- Sets a variable for boosted speed power


local function speed(otherPart)    ---Creates a function named speed with argument otherPart


    local partParent = otherPart.Parent    ---Uses the body part that touches part to get parent


    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")   ---Checks if a players touches part


    if humanoid then    ---Checks if the previous line was successful in finding player


        local currentSpeed = humanoid.WalkSpeed   ---Stores current player walk speed


        if currentSpeed < SPEEED_POWER then      ---Checks that player doesn't already have speed boost


            humanoid.WalkSpeed = SPEEED_POWER    ---If they don't then this sets walk speed to boosted value


            wait(10)    ---Player will keep speed boost for this long


            humanoid.WalkSpeed = currentSpeed    ---Returns speed back to normal


         end


    end


end

speedPart.Touched:Connect(speed)   ---Runs the function whenever the part is touched

Customize