Barrage attack works in studio but not in game

I’m making a Jojo game but the barrage damage works in studio but not in game.
A video of it in studio:
robloxapp-20240211-1835218.wmv (1.7 MB)
A video of it in game
robloxapp-20240211-1837119.wmv (2.6 MB)
I tried using different loops like for i=1, repeat loops and while loops but none of them worked.
pls help.

can u screenshot the console i nthe game


heres the line of code for the barrage

		local barraging = true
		rems:FindFirstChild("BarrageRem").OnServerEvent:Connect(function(plr)
			barraging = false
		end)
		hum.WalkSpeed = 5
		local stand = char:WaitForChild(standopowa.Value)
		local load = stand:FindFirstChild("AnimationController"):LoadAnimation(move:FindFirstChildWhichIsA("Animation"))
		stand.PrimaryPart.barrage:Play()
		load:Play()
		local thing = 0
		while task.wait(0.05) do
			thing += 1
			local hrp = char:FindFirstChild("HumanoidRootPart")
			local dir = hrp.CFrame.LookVector
			local no = {}
			local hb = Instance.new("Part", workspace.projectiles)
			hb.Touched:Connect(function(hit)
				if hit:FindFirstAncestorOfClass("Model") then
					local par = hit:FindFirstAncestorOfClass("Model")
					if no[par] == nil then
						if hit:FindFirstAncestorOfClass("Model"):FindFirstChildWhichIsA("Humanoid") and not par:FindFirstChild("iframes") then
							no[par] = true
							local hum = hit:FindFirstAncestorOfClass("Model"):FindFirstChildWhichIsA("Humanoid")
							hum:TakeDamage(1)
							local stunval = Instance.new("NumberValue")
							stunval.Name = "Stun"
							stunval.Value = 0.1
							stunval.Parent = par
							task.spawn(function()
								task.wait(1)
								stunval:Destroy()
							end)
						end
					end
				end
			end)
			local motor = Instance.new("WeldConstraint", hrp)
			hb.CanCollide = false
			motor.Name = "asumanumadubawanna"
			hb.CFrame = hrp.CFrame + (dir * (7 /2))
			motor.Part0 = hrp
			motor.Part1 = hb
			hb.Transparency = 0.5
			hb.Size = Vector3.new(4, 5, 7)
			if barraging == true then
				print("punchers")
			else
				print("no more punchers")
				motor:Destroy()
				hb:Destroy()
				break
			end
			wait(0.05)
			rems:FindFirstChild("BarrageRem").OnServerEvent:Connect(function(plr)
				barraging = false
			end)
			if barraging == true then
				print("punchers")
			else
				print("no more punchers")
				motor:Destroy()
				hb:Destroy()
				break
			end
			motor:Destroy()
			hb:Destroy()
			if thing == 65 then
				break
			end
		end
		stand.PrimaryPart.barrage:Stop()
		rems:FindFirstChild("BarrageRem"):FireClient(plr)
		hum.WalkSpeed = 16
		load:Stop()

i see multiple errors, try fixing them