-
What do you want to achieve?
im trying to make a punch system that if you hold it counts your punches and with that it plays the animation -
What is the issue?
the script works fine in roblox studio but in roblox app it does not work -
What solutions have you tried so far?
i tried to do pcall but that still did not help
also the animations are not the owner of the game but why would the script not work
local CAS = game:GetService("ContextActionService")
local PunchEvent = game.ReplicatedStorage.Events.PunchEvent
local character = script.Parent
local Humanoid = character:WaitForChild("Humanoid")
local animator = Humanoid:FindFirstChildOfClass("Animator")
local StatesFolder = character:WaitForChild("CharacterStates")
if not animator then
animator = Instance.new("Animator")
animator.Parent = Humanoid
end
local player = game.Players:GetPlayerFromCharacter(character)
animationFolder = script:WaitForChild("Animations")
local punchAnimation = {
animator:LoadAnimation(animationFolder:WaitForChild("punch1")),
animator:LoadAnimation(animationFolder:WaitForChild("punch2")),
animator:LoadAnimation(animationFolder:WaitForChild("punch3")),
animator:LoadAnimation(animationFolder:WaitForChild("punch4"))
}
local keybind = Enum.UserInputType.MouseButton1
local Holding = false
local CanPunch = true
local inloop = false
local CurrentConnection
local PunchesPerCombo = 4
ComboCount = 0
local EndTime = 1.4
local function Punch(ActionName, inputState)
if ActionName == "punch" and inputState == Enum.UserInputState.Begin then
Holding = true
if inloop then return end
inloop = true
task.spawn(function()
while Holding do
if not CanPunch or StatesFolder.Dashing.Value == true then
task.wait(0.1)
continue
end
ComboCount += 1
CanPunch = false
local track: AnimationTrack = punchAnimation[ComboCount]
track:Play()
if CurrentConnection then
CurrentConnection:Disconnect()
CurrentConnection = nil
end
CurrentConnection = track:GetMarkerReachedSignal("Hit"):Connect(function()
PunchEvent:FireServer(ComboCount)
end)
if ComboCount == PunchesPerCombo then
CanPunch = false
task.wait(EndTime)
CanPunch = true
ComboCount = 0
else
task.wait(0.45)
CanPunch = true
end
end
inloop = false
end)
elseif inputState == Enum.UserInputState.End then
Holding = false
end
end
CAS:BindAction("punch", Punch, true, keybind)
CAS:SetTitle("punch", "Punch")
CAS:SetPosition("punch", UDim2.new(0.2, 0, 0.4, 0))