How could I do this?

How could I turn this code that does a doge when you press E into a mobile button where when you press it, you dodge? here’s the script:
local UIS = game:GetService(“UserInputService”)
local char = script.Parent

local slideAnim = Instance.new(“Animation”)
slideAnim.AnimationId = “rbxassetid://17819417962” – Enter your AnimtionID

local keybind = Enum.KeyCode.E – between the key for ability
local canslide = true

UIS.InputBegan:Connect(function(input,gameprocessed)
if gameprocessed then return end
if not canslide then return end

if input.KeyCode == keybind then
	canslide = false
	
	local playAnim = char.Humanoid:LoadAnimation(slideAnim)
	playAnim:Play()
	
	local slide = Instance.new("BodyVelocity")
	slide.MaxForce = Vector3.new(1,0,1) * 30000
	slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 100
	slide.Parent = char.HumanoidRootPart
	
	for count = 1, 8 do
		wait(0.1)
		slide.Velocity*= 0.7
	end
	playAnim:Stop()
	slide:Destroy()
	canslide = true
end

end)

You need to create a TextButton so that whenever it is pressed, the player dodges

local UIS = game:GetService("UserInputService")
local char = script.Parent.Parent.Parent -- 
local button = script.Parent -- The TextButton (change the path to yours)
local slideAnim = Instance.new("Animation")
slideAnim.AnimationId = "rbxassetid://17819417962" 

local canslide = true

local function dodge()
    if not canslide then return end

    canslide = false

    local playAnim = char.Humanoid:LoadAnimation(slideAnim)
    playAnim:Play()

    local slide = Instance.new("BodyVelocity")
    slide.MaxForce = Vector3.new(1, 0, 1) * 30000
    slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 100
    slide.Parent = char.HumanoidRootPart

    for count = 1, 8 do
        wait(0.1)
        slide.Velocity *= 0.7
    end
    playAnim:Stop()
    slide:Destroy()
    canslide = true
end

button.MouseButton1Click:Connect(dodge)
1 Like