My goal is to make sprinting by shifting in every devices ( except xbox and something else )
This is my completed script for making sprinting & stamina system :
local cam = game.Workspace.CurrentCamera
local players = game.Players.LocalPlayer
local humanoid = players.Character:FindFirstChildOfClass("Humanoid")
local userinputservice = game:GetService("UserInputService")
local tweenservice = game:GetService("TweenService")
local replicatedstorage = game:GetService("ReplicatedStorage")
local contextactionservice = game:GetService("ContextActionService")
local runservice = game:GetService("RunService")
local statscript = replicatedstorage:FindFirstChild("StatScript")
local stat = require(statscript)
local isrunning_fov = tweenservice:Create(cam, stat.fovinfo, {FieldOfView = stat.normalfov + 20})
local isnotrunning_fov = tweenservice:Create(cam, stat.fovinfo, {FieldOfView = stat.normalfov})
local isrunning_gui = tweenservice:Create(script.Parent, stat.staminafadinginfo, {BackgroundTransparency = 0})
local isnotrunning_gui = tweenservice:Create(script.Parent, stat.staminafadinginfo, {BackgroundTransparency = 1})
local isrunning_guistroke = tweenservice:Create(script.Parent.UIStroke, stat.staminafadinginfo, {Transparency = .8})
local isnotrunning_guistroke = tweenservice:Create(script.Parent.UIStroke, stat.staminafadinginfo, {Transparency = 1})
local isrunning = nil
local allow_running = true
local max = 0.968
local sizechangingamount = 20/100 * max
local cd_running = 50/100 * max
local function walkspeed (num)
humanoid.WalkSpeed = num
end
local function sprint (active)
if active then
isrunning = true
isrunning_fov:Play()
isrunning_gui:Play()
isrunning_guistroke:Play()
walkspeed(stat.normalspeed + 4)
else
isrunning = false
isnotrunning_fov:Play()
isnotrunning_gui:Play()
isnotrunning_guistroke:Play()
walkspeed(stat.normalspeed)
end
end
task.wait()
script.Parent.BackgroundTransparency = 1
script.Parent.UIStroke.Transparency = 1
runservice.Heartbeat:Connect(function (deltaTime)
if isrunning == true then
if script.Parent.Size.X.Scale > 0 then
script.Parent.Size -= UDim2.fromScale(sizechangingamount * deltaTime,0)
else
allow_running = false
end
elseif isrunning == false then
if script.Parent.Size.X.Scale < max then
script.Parent.Size += UDim2.fromScale(sizechangingamount * deltaTime,0)
else
end
end
if script.Parent.Size.X.Scale > cd_running then
allow_running = true
end
end)
userinputservice.InputBegan:Connect(function (input)
if input.KeyCode == Enum.KeyCode.LeftShift and humanoid.MoveDirection.Magnitude > 0 then
if allow_running == true then
sprint(true)
repeat task.wait() until not userinputservice:IsKeyDown(Enum.KeyCode.LeftShift) or allow_running == false
end
sprint(false)
end
end)
I want to know how to make a button for those devices like mobile and tablet. This looks simple for some people, but I want to know how to make it with understandable explains.