TouchTap doesn't work when player die

Hello,
I added some controls for mobile to my game on localscript and they works fine first time on mobile, but when the player die the controls stop working.

You might need to add the controls to StarterCharacterScripts instead of StarterPlayerScripts

It’s already in this folder, I printed a log to show that this script is loading every time the player dies, but it ignores the controls :confused:

local function onInputBegan(input, isTyping)
	if isTyping then return end
	if input.KeyCode == Enum.KeyCode.LeftShift then
		if IsOn then return end
		activateDash()
	end
end

local function onTouchDash()
	if IsOn then return end
	activateDash()
end
local dashButton = game.Players.LocalPlayer.PlayerGui:WaitForChild("PowerUps").dashCD.TouchButton
dashButton.TouchTap:Connect(onTouchDash)

Oh I see, you would like the dash to work if the player presses LeftShift or taps the dash button. Personally, I would use ContextActionService to do so instead of UserInputService as it allows you to make the button for mobile in a more convenient way, but if you prefer using UserInputService then you will need to do something like this (there might be an easier way to do it, but since I prefer using CAS it’s been a long time since I used UIS):

local powerUps = game:GetService"Players".LocalPlayer:WaitForChild"PlayerGui":WaitForChild"PowerUps"

local function startDash()
	-- Write the code to start the dash here
end

local function stopDash()
	-- Write the code to stop the dash here
end

userInputService.InputBegan:Connect(function(inputObject, gpe)
	if gpe then return end

	if inputObject.KeyCode == Enum.KeyCode.LeftShift then startDash() end
end)
userInputService.InputEnded:Connect(function(inputObject, gpe)
	if gpe then return end

	if inputObject.KeyCode == Enum.KeyCode.LeftShift then stopDash() end
end)

local debounce -- The debounce is here because I found sometimes touches register twice for some reason
powerUps:WaitForChild"dashCD":WaitForChild"TouchButton".InputBegan:Connect(function(inputObject)
	if debounce then return end

	if inputObject.UserInputType == Enum.UserInputType.Touch then
		debounce = true

		userInputService.TouchEnded:Once(function() -- This is to prevent a bug
			stopDash()
			debounce = nil
		end)

		startDash()
	end
end)
1 Like

Thanks! Looks like it made conflicts between the keyboard and touch controls, now is working :smiley:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.