Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a person dash forwards after pressing a key?

So I have a script that makes you dash forwards after double tapping W. Whenever I double tap W in front of a wall I will either go through it or my character will go flying across the map. I would just like to figure out how to make it so that doesn't happen anymore. Any help would be appreciated.

Local Script:

local player = game.Players.LocalPlayer
local character = player.Character
local hum = character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local HRP = character:WaitForChild("HumanoidRootPart")

local W = 0
local FrontFlipping = tick() - W
local Ww = false

UIS.InputBegan:connect(function(input, event)
    if Ww then return end
    if input.KeyCode == Enum.KeyCode.W and not event then
        FrontFlipping = tick() - W
        if FrontFlipping < 0.2 then 

            Ww = true

            local Table = {}
            hum.WalkSpeed = 0           

            for i,v in pairs(character:GetChildren()) do
                if v:IsA("Part") then
                    local BodyForce = Instance.new("BodyForce",v)
                    BodyForce.Force = Vector3.new(0,workspace.Gravity*v:GetMass(),0)
                    table.insert(Table, BodyForce)
                end
            end

            for i = 1,16 do
                for i,v in pairs(character:GetChildren()) do
                    if v:IsA("BasePart") then
                        v.Velocity = Vector3.new(0,0,0)
                    end
                end
                character:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -3))
                wait(1/100)
            end

            for i,v in pairs(Table) do
                v:Destroy()
            end     

            hum.WalkSpeed = 16
            W = 0
            wait(0.25)
            Ww = false
            return
        end
        W = tick()
    end 
end)

Regular script that clones local script into player:

game.Players.PlayerAdded:connect(function(plr)
    local A = script.Script:Clone()
    A.Parent = plr.Character    
    plr.CharacterAdded:connect(function(char)
        local A = script.Script:Clone()
        A.Parent = char
    end)
end)

3 comments

0

lol no

0

I'm wondering if raycasting would work for this

1 answer

You'll want to create a new argument in your if statement, one that will determine the distance between your character's HumanoidRootPart and the part directly in front of it.

2 comments

0

Can you please clarify which if statement you are talking about?

0

Line 13 in your first script. :)

This discussion is preserved as it was. New answers, comments, and votes are closed.