Hello,
I have currently been trying to get some of my movement system to work on mobile in my game and ran into an issue where in my function it will not play my animations or fire my events. I am using ContextActionService for this and have not encountered this issue any other time I have used CAS. I recently just made a crouching system with CAS which is almost exactly the same code as my sliding script and it works perfectly fine. I even plugged the slide animation into it and it worked fine. This issue only persits in my sliding script. I tried creating a new script which I arranged and cleaned up the code but still the same error. I have looked on the web but have found nothing that gives me a good solution. If anyone else has encountered this issue or knows how to fix it, please let me know.
Here is my sliding code(new to studio so please excuse my bad coding and organization):
local player = game.Players.LocalPlayer
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local rootPart = humanoid.RootPart
local Camera = workspace.CurrentCamera
--services
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")
local GuiService = game:GetService("GuiService")
--sliding varibles
local isSliding = false
local justSlided = false
local slideForce = 1.6
local slideCooldown = .8
local grounded = true
local justSlided = false
local canNotSlide = false
local lateGrounded = true
local CameraInfo = TweenInfo.new(0.3)
local CameraTweenDown = game:GetService("TweenService"):Create(player.Character.Humanoid, CameraInfo, {CameraOffset = Vector3.new(0,-2.5,1)})
local CameraTweenUp = game:GetService("TweenService"):Create(player.Character.Humanoid, CameraInfo, {CameraOffset = Vector3.new(0,0,0)})
local isSlidingEvent = ReplicatedStorage:WaitForChild("isSliding")
local stoppedSlidingEvent = ReplicatedStorage:WaitForChild("stoppedSliding")
local SlidingStart = ReplicatedStorage:WaitForChild("SlidingStart")
local SlidingStop = ReplicatedStorage:WaitForChild("SlidingStop")
local Slide = humanoid:LoadAnimation(script:WaitForChild("SlideAnim"))
--check if grounded
humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
grounded = false
end
end)
humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Landed then
grounded = true
lateGrounded = false
end
end)
--actual sliding code
local function Slide(name, state, input)
if state == Enum.UserInputState.Begin and not isSliding then
isSliding = true
Slide:Play()
local hVel = character.HorizontalVelocity
hVel.Value = hVel.Value * slideForce
CameraTweenDown:Play()
SlidingStart:FireServer()
isSlidingEvent:Fire()
else
isSliding = false
justSlided = true
CameraTweenUp:Play()
Slide:Stop()
SlidingStop:FireServer()
stoppedSlidingEvent:Fire()
canNotSlide = true
task.wait(slideCooldown)
canNotSlide = false
end
end
--binding
ContextActionService:BindAction("Sliding", Slide, true, Enum.KeyCode.LeftShift)
ContextActionService:SetPosition("Sliding", UDim2.new(.1, 0, .5, 0))
ContextActionService:SetTitle("Sliding", "Slide")
--check if on mobile
if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled and not UIS.GamepadEnabled and not GuiService:IsTenFootInterface() then
local CrouchButton = ContextActionService:GetButton("Sliding")
CrouchButton.Size = UDim2.new(.35,0,.35,0)
end
Screenshot of error in output: