My dash button is broken

so I’m trying to make my dash button work but it did, just not in the button

heres the video btw
robloxapp-20210918-1418289.wmv (1.7 MB)

here’s the code, let me know if there’s something wrong with it

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAddeed:Wait(2)
local UserInputSerivce = game:GetService("UserInputService")

local Mobile = script.Parent.Parent.Parent.StarterGui.DashButtonMobileOnly.DashFrame.DashMainButton.ImageButton

local onCooldown = false
local humanoid = script.Parent:WaitForChild("Humanoid")
local anim = humanoid:LoadAnimation(script:WaitForChild("Animation"))

UserInputSerivce.InputBegan:Connect(function(Input, GameStuff)
   if GameStuff then return end
   
   if Input.KeyCode == Enum.KeyCode.LeftShift or Mobile.MouseButton1Click then
   	if not onCooldown then
   		onCooldown = true
   		Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector*100 
   		anim:Play()
   		print("Dash!")
   		wait(2)
   		onCooldown = false
   	end
   end
end)


1 Like

Could you debug this yourself first please and tell us if there’s anything wrong with it instead of us doing that for you? Please use the Developer Console (F9 on your keyboard or /console in the chat) to see if there are any errors with your code and use prints to see what things do and don’t run if it’s an issue of your code not working correctly.

there’s no errors in the developer console it just prints dash every time i click on the screen and not the button

I assume this here? You should read documentation. MouseButton1Click is an event not a property much like InputBegan is. If you want a mobile button to also trigger your sprinting function then you need to be connecting a function to that button separately.

Better is to make the sprint function on its own thing and then call it both in the context of InputBegan and when the sprint button is pressed.

1 Like

i got it figured it out after i Research some Stuff
this the code

local player = game.Players.LocalPlayer
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAddeed:Wait()
local UIS = game:GetService("UserInputService")
local humanoid = player.Character.Humanoid
local gui = plr.PlayerGui.MobileDashGui.DashFrame.DashMainButton.ImageButton

local debounce = false
local cooldown = 1 

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://7493551363"
--PC
UIS.InputBegan:Connect(function(input,IsTyping)
	if IsTyping then
		return
	elseif input.KeyCode == Enum.KeyCode.LeftShift then
		if debounce == false then
				debounce = true
		local playAnim = humanoid:LoadAnimation(anim)
			playAnim:Play()
			Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector*100
			wait(cooldown)
	debounce = false
		end
	end
end)
--Mobile
gui.MouseButton1Click:Connect(function()
	if debounce == false then
		debounce = true
		local playAnim = humanoid:LoadAnimation(anim)
		playAnim:Play()
		Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector*100
		wait(cooldown)
		debounce = false
	end
end)

i feel so dumb ;-;

1 Like