Problem with dash on a mobile device

wait()

local player = game.Players.LocalPlayer
local character = player.Character

local UIS = game:GetService("UserInputService")
local ts = game:GetService("TweenService")

local remote = game.ReplicatedStorage.DashRemote
local FX = game.ReplicatedStorage.Fx
local animation = game.ReplicatedStorage.Animations 

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Whitelist
params.FilterDescendantsInstances = {workspace.Map}

local debounce = false
local button = game.StarterGui.MobileGui.ImageButton
local neededStamina = 10


local data = game.Players.LocalPlayer:WaitForChild("Data")
local stamina = data:WaitForChild("Stamina")
local maxStamina = data:WaitForChild("MaxStamina")


UIS.InputBegan:Connect(function(input, gpe)
	if gpe then return end

	if button.TouchTap and not debounce then
		print(button.Name)
		print("ffff")
		if stamina.Value >= 10 then
			debounce = true
			local anim
			local v = Instance.new("BodyVelocity", character.HumanoidRootPart)
			v.MaxForce = Vector3.new(999999, 0 , 999999)
			if UIS:IsKeyDown(Enum.KeyCode.Q) or character.Humanoid.MoveDirection.Magnitude == 0 then
				anim = animation.Dash
				v.Velocity = character.HumanoidRootPart.CFrame.LookVector * 80
			end

			character.Humanoid.Animator:LoadAnimation(anim):Play()
			game.Debris:AddItem(v, .3)
			remote:FireServer(character, v.Velocity, neededStamina, player)
			wait(0.6) -- cooldown
			debounce = false
		end

	end
end)


remote.OnClientEvent:Connect(function(data)
	if data.Action == "Dash" then
		local hrp = data.Character.HumanoidRootPart

		for i = 1, 20 do
			for i = 1, math.random(1, 3) do
				local hb = FX.Sphere:Clone()
				hb.Parent = workspace.Fx
				hb.Anchored = true
				hb.CanCollide = false
				hb.Transparency = 0
				hb.Name = "hb"
				hb.Material = Enum.Material.Neon
				hb.CanQuery = false
				hb.Size = Vector3.new(.07, .07, math.random(4, 6))
				local colorRand = math.random(1, 3)
				if colorRand == 1 then
					hb.Color = Color3.fromRGB(0, 0, 0)
				else
					hb.Color = Color3.fromRGB(180, 180, 180)
				end
				hb.CFrame = CFrame.new(hrp.Position, hrp.Position + data.Direction) * CFrame.new(math.random(-25, 25)/10, math.random(-4, 2), math.random(-2, 2))
				game.Debris:AddItem(hb, .4)
				ts:Create(hb, TweenInfo.new(.4), {Transparency = 1, Size = Vector3.zero, CFrame = hb.CFrame * CFrame.new(0, 0, math.random(2, 4))}):Play()
			end

			local ray = workspace:Raycast(hrp.Position, Vector3.new(0, -4, 0), params)
			--if ray then
			--	local dust = FX.Dust:Clone()
			--	dust.Parent = workspace.Fx
			--	dust.CFrame = hrp.CFrame
			--	dust.Position = ray.Position
			--	dust.Attachment.Dust.Color = ColorSequence.new(ColorSequenceKeypoint.new(0, ray.Instance.Color), ColorSequenceKeypoint.new(1, ray.Instance.Color))
			--	dust.Attachment.Dust:Emit(10)
			--	game.Debris:AddItem(dust, 2)
			--end
			task.wait()
		end
	end
end)

So here I have a script that when you click on the Dash button, the problem is that when you click on the button it does not happen, but when you click on any other part of the screen happens.

What is the problem?

The same script only with the button “Q”, on the computer, works perfectly

1 Like

Hey Dssall2!

Right off the bat, button.TouchTap isn’t a variable, it’s an event. Here is the API: GuiObject | Roblox Creator Documentation
That event fires once the button is tapped, so you won’t be able to check the value like a variable. In light of that, you can replace the UIS.InputBegan with button.TouchTap . The API gives some example code with it being used.

I’m not sure why it was working when pressing any other part of the screen, so that’s odd.

1 Like