Good morning!
I’ve been working on a charging attack, where if you hold mouseButton1Down for 1 or more seconds you deal more damage.
When I tried this on computer, it worked perfectly; however when I tried it on mobile it did detect the hold time, but the tool.Activated() function only activated when it was a short tap, making the hold time redundant.
here’s the script for counting the hold time: (I got this from another forum, I dont take credit for this)
tool.Equipped:Connect(function()
equipped = true
startedDown = 0
---mouse
mouse.Button1Down:connect( function()
if equipped == true then
mouseDown = true
startedDown = tick()
end
end)
mouse.Button1Up:connect( function()
mouseDown = false
end)
---touch
uis.TouchStarted:connect( function()
if equipped == true then
mouseDown = true
startedDown = tick()
end
end)
uis.TouchEnded:connect( function()
mouseDown = false
end)
---
while wait() do
if mouseDown == true and equipped == true then
hold_time = tick() - startedDown
end
end
end)
tool.Unequipped:Connect(function()
equipped = false
end)
and this part to trigger the attack became the issue:
tool.Activated:Connect(function()
if canPunch == true then canPunch = false
game.ReplicatedStorage.Pstatus:FireServer("Attack", true) -- telling server that player is attacking
repeat wait() until mouseDown == false or hold_time >= 1 or equipped == false;
if hold_time >= 1 then
-- extra damage punch
elseif equipped == false or hold_time < 1 or mouseDown == false then
-- normal punch script
end
end
end
end)
I’m pretty sure this is because tool.Activated() on computer activates on mouseButton1down, while on mobile it activates when the player fully taps and lets go of the screen. Would there be a way for me to change this, so it can work on both mobile and computer?
I tried using contextactionservice, but I dont want to make a button for it.