Why the scripts work in Studio but not in Roblox?

I try in studio, and it works but I try in Roblox, and it doesn’t work
all help is useful :smiley:
the game is under a group

script

local CombatModule = {}

function CombatModule.combat(chr)
local humanoid = chr:FindFirstChildOfClass(“Humanoid”)
if not humanoid then
warn(“No humanoid found in character”)
return – If no humanoid, stop function
end

local Rs = game:GetService("ReplicatedStorage")
local anim = humanoid:LoadAnimation(Rs.Anims.Punch1)
anim:Play()

-- Trigger the hitbox creation on the "Punch" marker
anim:GetMarkerReachedSignal("Punch"):Connect(function()
	local debris = game:GetService("Debris")

	-- Ensure the character has a HumanoidRootPart
	local humanoidRootPart = chr:FindFirstChild("HumanoidRootPart")
	if not humanoidRootPart then
		warn("No HumanoidRootPart found")
		return
	end

	-- Create the hitbox as a part in the workspace, not in the character
	local Hitbox = Instance.new("Part")
	Hitbox.Size = Vector3.new(7, 7, 7)
	Hitbox.Color = Color3.new(1, 0, 0)
	Hitbox.CanCollide = false
	Hitbox.Anchored = true
	Hitbox.Transparency = 0.5  -- Transparency to visualize it for debugging
	Hitbox.CFrame = humanoidRootPart.CFrame * CFrame.new(0, 0, -4)

	-- Parent the hitbox to workspace and add it to debris
	Hitbox.Parent = game.Workspace
	debris:AddItem(Hitbox, 0.2) -- Destroy it after 0.2 seconds

	-- Debugging to check if the hitbox is created
	print("Hitbox created at: " .. tostring(Hitbox.Position))

	-- Detect the hitbox collision with other objects
	Hitbox.Touched:Connect(function(hit)
		local target = hit.Parent
		-- Prevent collision with the character itself
		if target == chr then return end

		-- Ensure target has a "Humanoid" and isn't stunned
		local targetHumanoid = target:FindFirstChild("Humanoid")
		if targetHumanoid then
			-- Only continue if not already stunned
			local stunned = target.Parent:FindFirstChild("Stunned")
			if stunned and stunned.Value == false then
				-- Apply damage
				print("Hit detected on " .. target.Parent.Name)
				targetHumanoid.Health = targetHumanoid.Health - 20

				-- If health drops to 0, play the finish sound and increase kills
				if targetHumanoid.Health <= 0 then
					local punchFinishSound = Rs.Sounds.PunchFinish:Clone()
					punchFinishSound.Parent = target.Parent:FindFirstChild("HumanoidRootPart")
					punchFinishSound:Play()

					local player = game.Players:GetPlayerFromCharacter(chr)
					if player then
						player.leaderstats.Kills.Value = player.leaderstats.Kills.Value + 1
						player.leaderstats.AllTimeKills.Value = player.leaderstats.AllTimeKills.Value + 1
					end

					punchFinishSound.Ended:Connect(function()
						punchFinishSound:Destroy()
					end)
				end

				-- Play punch sound and animation
				local punchSound = Rs.Sounds.Punch:Clone()
				punchSound.Parent = target.Parent:FindFirstChild("HumanoidRootPart")
				punchSound:Play()
				punchSound.Ended:Connect(function()
					punchSound:Destroy()
				end)

				-- Apply stun effect
				local anim = targetHumanoid:LoadAnimation(Rs.Anims.Hit)
				anim:Play()

				-- Reduce walk speed and apply stun
				targetHumanoid.WalkSpeed = 10
				stunned.Value = true

				-- Highlight the target to indicate stun
				local highlight = Instance.new("Highlight")
				highlight.Parent = target.Parent
				highlight.OutlineTransparency = 1
				highlight.FillColor = Color3.new(1, 0, 0)
				highlight.FillTransparency = 0

				-- Fade out the highlight
				local TweenService = game:GetService("TweenService")
				local TweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
				local tween = TweenService:Create(highlight, TweenInfo, {FillTransparency = 1})
				tween:Play()

				-- Remove highlight after tween completes
				tween.Completed:Connect(function()
					highlight:Destroy()
				end)

				-- Restore walk speed and remove stun after animation
				anim.Ended:Connect(function()
					targetHumanoid.WalkSpeed = 16
					stunned.Value = false
				end)
			end
		end
	end)
end)

Have you checked the Developer Console in Roblox (F9) to see if there are any errors?
If I had to guess right now it might have something to do with the animations or sound

Is the animation owned by the group or user who owns the game? If not it won’t let the animation play.

oh thats why thanks bluemoon
:partying_face: :partying_face: :partying_face: