#how do i properly make a dash button in battleground games for mobile

1 messages · Page 1 of 1 (latest)

limber eagle
#
local PLRS=game:GetService("Players")
local RS=game:GetService("ReplicatedStorage")
local UIS=game:GetService("UserInputService")
local Remotes=RS:WaitForChild("Remotes")
local Dash=Remotes:WaitForChild("Dash")

local player=PLRS.LocalPlayer

local char=player.Character

local hum=char:WaitForChild("Humanoid")
local HRP=char:WaitForChild("HumanoidRootPart")

local MobileGUI=script.Parent:WaitForChild("MobileGUI")

UIS.InputBegan:Connect(function(input, GPE)
    if UIS:IsKeyDown(Enum.KeyCode.W) and UIS:IsKeyDown(Enum.KeyCode.Q) or hum.MoveDirection.Magnitude==0 and UIS:IsKeyDown(Enum.KeyCode.Q) then
        Dash:FireServer("FrontDash", 1)
    elseif UIS:IsKeyDown(Enum.KeyCode.S) and UIS:IsKeyDown(Enum.KeyCode.Q) then
        Dash:FireServer("BackDash", 1)
    elseif UIS:IsKeyDown(Enum.KeyCode.A) and UIS:IsKeyDown(Enum.KeyCode.Q) then
        Dash:FireServer("LeftDash", 2)
    elseif UIS:IsKeyDown(Enum.KeyCode.D) and UIS:IsKeyDown(Enum.KeyCode.Q) then
        Dash:FireServer("RightDash", 2)
    end 
end)

MobileGUI.MobileFrame.DashButton.MouseButton1Click:Connect(function()
    local hrpCFrame = HRP.CFrame:Inverse() * (HRP.Position + HRP.Velocity)
    local velocity=HRP.CFrame:VectorToObjectSpace(hrpCFrame)
    local yDirection=math.atan2(velocity.X,-velocity.Z)
    local roundDirection=math.ceil(math.deg(yDirection)-0.5)
    print(roundDirection)
    if roundDirection>-45 and roundDirection<45 then
        Dash:FireServer("FrontDash", 1)
    elseif roundDirection<-135 and roundDirection>=-180 then
        Dash:FireServer("BackDash", 1)
    elseif hum.MoveDirection==Vector3.new(-1,0,0) then
        Dash:FireServer("LeftDash", 2)
    elseif hum.MoveDirection==Vector3.new(1,0,0) then
        Dash:FireServer("RightDash", 2)
    end
end)
#

its the mousebutton1click one