i have a very stressful problem using the contextbindactionservice literally i have used userinputService but the creator want me to make it for mobile to which is very hard for me to do it
the first error i got is the context bind already being triggered which then dont work anymore
and the second problem is that it is not showing for mobile user
all i want is when mobile user or PC hold it they can sprint and play the animation when they are not moving they cant sprint and animation stops
but there a lack of feature with this context action here is my script
local action = game:GetService("ContextActionService")
local Bar = script.Parent:WaitForChild('Background'):WaitForChild('Bar')
local player = game.Players.LocalPlayer
local NormalWalkSpeed = 16
local NewWalkSpeed = 25
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://6116929990"
local power = 10
local sprinting = false
repeat wait() until game.Players.LocalPlayer.Character
local character = player.Character
local anim = character.Humanoid:LoadAnimation(animation)
local function CanSprint()
game:GetService("RunService").RenderStepped:Connect(function(dt)
character.Humanoid.WalkSpeed = NewWalkSpeed
sprinting = true
anim:Play()
while power > 0 and sprinting do
power = power - .03
Bar:TweenSize(UDim2.new(power / 10, 0, 1, 0), 'Out', 'Quint', .1, true)
Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 0, 0), 0.001)
wait()
if power <= 0 then
character.Humanoid.WalkSpeed = NormalWalkSpeed
if (character ~= nil) then
local speed = (character.HumanoidRootPart.Velocity).magnitude;
if (speed == 0) then
anim:Stop()
end
end
end
end
end)
action:BindAction("Sprint", CanSprint, true, Enum.KeyCode.LeftShift)
action:SetPosition("Sprint", UDim2.new(0.500,0,0.245,0))
local function cannotSprint()
character.Humanoid.WalkSpeed = NormalWalkSpeed
sprinting = false
anim:Stop()
while power < 10 and not sprinting do
power = power + .03
Bar:TweenSize(UDim2.new(power / 10, 0, 1, 0), 'Out', 'Quint', .1, true)
Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(61, 47, 255), 0.001)
wait()
if power <= 0 then
if anim:Play() then
anim:Stop()
end
character.Humanoid.WalkSpeed = NormalWalkSpeed
end
end
end
action:BindAction("NotSprint", cannotSprint, true, Enum.KeyCode.LeftShift)
action:SetPosition("NotSprint", UDim2.new(0.500,0,-0.200,0))
end