i created a gui to work on the features of swords on mobile, I wrote scripts, but I want it to speed up when I press Textbutton, I don’t want it to speed up when I press the screen
here is the video
Gui Script:
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local guiButton = script.Parent
local function isMobile()
return UserInputService.TouchEnabled
end
local function activateSwordAbility()
print("Worked")
local player = Players.LocalPlayer
local character = player.Character
if character and isMobile() then
local tool = character:FindFirstChild("ClassicSword")
if tool then
tool:Activate()
end
end
end
if isMobile() then
guiButton.MouseButton1Click:Connect(activateSwordAbility)
else
guiButton.MouseButton1Click:Connect(function() end)
end
Sword Script:
-- ClassicSword adındaki kılıcınızın içine ekleyeceğiniz bir Script
local Tool = script.Parent
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local speedBoostAmount = 40
local speedBoostDuration = 1.5
local cooldownDuration = 10
local canActivate = true
local humanoid = nil
local function onActivated()
if canActivate and humanoid then
canActivate = false
humanoid.WalkSpeed = humanoid.WalkSpeed + speedBoostAmount
wait(speedBoostDuration)
humanoid.WalkSpeed = humanoid.WalkSpeed - speedBoostAmount
wait(cooldownDuration)
canActivate = true
end
end
local function onEquipped()
humanoid = Tool.Parent:FindFirstChild("Humanoid")
end
local function onUnequipped()
humanoid = nil
end
Tool.Activated:Connect(onActivated)
Tool.Equipped:Connect(onEquipped)
Tool.Unequipped:Connect(onUnequipped)