I just want it to work when the gui presses

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)

You have to make a remote event, put it in ReplicatedStorage and fire it to the server when the gui button is clicked. Make it so when its fired you connect a function to OnServerEvent in the server sword script. Now you activate the tool in that connected function.

If you dont do this your Tool does not that you are trying to activate the tool and run the function you connected with Activated because the sword script is a server script and you activated in a local script.

i’ve updated the gui script again, it speeds up when I press the screen, the guie doesn’t speed up when I press, I don’t know what to do

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local activateSwordEvent = ReplicatedStorage:WaitForChild("ActivateSwordEvent")
local guiButton = script.Parent

local function isMobile()
	return UserInputService.TouchEnabled
end

local function activateSwordAbility()
	print("Worked")
	if isMobile() then
		activateSwordEvent:FireServer()
	end
end

if isMobile() then
	guiButton.TouchTap:Connect(activateSwordAbility)
else
	guiButton.MouseButton1Click:Connect(function() end)
end

maybe try connecting the on activated function with the remote event on the server script instead of doing tool:Activate().

can you examine it a little more or I won’t be able to solve it :(.