Script works in roblox studio but not in roblox app

  1. 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

  2. What is the issue?
    the script works fine in roblox studio but in roblox app it does not work

  3. 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))
1 Like

If you look in the console in game (not in Studio - Press F9 to open console in game), are there any errors that may indicate why it isn’t working?

Also - are you 100% sure that you’ve published, and that it is published to the right place? (Has happened before where people just forgot to publish)

2 Likes

This might because the full script isn’t published. try checking if the script works, then publish it

1 Like

the script worked in studio but not in Roblox even if I published it and all the errors are just animations failed to load but I remember that didn’t make the script fail

republish the animations and change the ids

1 Like